50 #include <Rcs_Mat3d.h> 51 #include <Rcs_Vec3d.h> 52 #include <Rcs_typedef.h> 53 #include <Rcs_macros.h> 54 #include <TaskDistance1D.h> 55 #include <TaskEuler1D.h> 56 #include <TaskFactory.h> 57 #include <TaskPosition1D.h> 58 #include <TaskVelocity1D.h> 60 #ifdef GRAPHICS_AVAILABLE 62 #include <RcsViewer.h> 79 std::string actionModelType =
"unspecified";
83 RcsBody* ground = RcsGraph_getBodyByName(
graph,
"Ground");
85 RcsBody* club = RcsGraph_getBodyByName(
graph,
"Club");
87 RcsBody* clubTip = RcsGraph_getBodyByName(
graph,
"ClubTip");
89 RcsBody* ball = RcsGraph_getBodyByName(
graph,
"Ball");
92 if (actionModelType ==
"joint_pos") {
96 else if (actionModelType ==
"ik") {
104 auto tmpTask =
new TaskVelocity1D(
"Zd",
graph, ball, clubTip,
nullptr);
105 tmpTask->resetParameter(Task::Parameters(-100.0, 100.0, 1.0,
"Z Velocity [m/s]"));
106 amIK->addTask(tmpTask);
108 amIK->addTask(
new TaskPosition1D(
"Y",
graph, ball, clubTip,
nullptr));
109 amIK->addTask(
new TaskDistance1D(
graph, club, ground, 2));
110 amIK->addTask(TaskFactory::createTask(
111 R
"(<Task name="ClubTip_Polar" controlVariable="POLAR" effector="ClubTip" active="true" />)", 117 amIK->addTask(
new TaskPosition1D(
"X",
graph, clubTip,
nullptr,
nullptr));
120 amIK->addTask(
new TaskPosition1D(
"Y",
graph, ball, clubTip,
nullptr));
121 amIK->addTask(
new TaskDistance1D(
graph, club, ground, 2));
122 amIK->addTask(TaskFactory::createTask(
123 R
"(<Task name="ClubTip_Polar" controlVariable="POLAR" effector="ClubTip" active="true" />)", 136 throw std::invalid_argument(
"Velocity tasks are not implemented for AMIKGeneric in this environment.");
142 std::cout <<
"IK considers the provided collision model" << std::endl;
151 std::ostringstream os;
152 os <<
"Unsupported action model type: " << actionModelType;
153 throw std::invalid_argument(os.str());
164 omLinBall->setMinState({-5, -5, 0});
165 omLinBall->setMaxState({3, 3, 0.1});
166 omLinBall->setMaxVelocity(10);
167 fullState->addPart(omLinBall);
171 omLinBall->setMinState({-3, -3, 0});
172 omLinBall->setMaxState({3, 3, 0.1});
173 fullState->addPart(omLinBall);
179 omLinClub->setMinState({-3, -3, 0});
180 omLinClub->setMaxState({3, 3, 2});
181 omLinClub->setMaxVelocity(5);
182 fullState->addPart(omLinClub);
186 omLinClub->setMinState({-3, -3, 0});
187 omLinClub->setMaxState({3, 3, 2});
188 fullState->addPart(omLinClub);
194 omAng->setMaxVelocity(20);
195 fullState->addPart(omAng);
199 fullState->addPart(omAng);
203 std::list<std::string> listOfJointNames = {
"base-m3",
"m3-m4",
"m4-m5",
"m5-m6",
"m6-m7",
"m7-m8",
"m8-m9"};
204 for (std::string jointName : listOfJointNames) {
208 std::string actionModelType =
"unspecified";
213 RcsSensor* fts = RcsGraph_getSensorByName(
graph,
"WristLoadCellSchunk");
216 fullState->addPart(
OMPartial::fromMask(omForceTorque, {
true,
true,
true,
false,
false,
false}));
243 #ifdef GRAPHICS_AVAILABLE 245 double cameraCenter[3];
246 cameraCenter[0] = 1.5;
247 cameraCenter[1] = 0.5;
248 cameraCenter[2] = 0.0;
251 double cameraLocation[3];
252 cameraLocation[0] = -1.5;
253 cameraLocation[1] = 4.5;
254 cameraLocation[2] = 2.8;
258 Vec3d_setUnitVector(cameraUp, 2);
261 viewer->setCameraHomePosition(osg::Vec3d(cameraLocation[0], cameraLocation[1], cameraLocation[2]),
262 osg::Vec3d(cameraCenter[0], cameraCenter[1], cameraCenter[2]),
263 osg::Vec3d(cameraUp[0], cameraUp[1], cameraUp[2]));
269 std::vector<std::string>& linesOut,
double currentTime,
const MatNd* obs,
const MatNd* currentAction,
274 if (simulator !=
nullptr) {
275 simName = simulator->getClassName();
281 linesOut.emplace_back(
282 string_format(
"physics engine: %s sim time: %2.3f s", simName, currentTime));
284 unsigned int numPosCtrlJoints = 0;
285 unsigned int numTrqCtrlJoints = 0;
287 RCSGRAPH_TRAVERSE_JOINTS(
graph) {
288 if (JNT->jacobiIndex != -1) {
289 if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_POSITION) {
292 else if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_TORQUE) {
297 linesOut.emplace_back(
298 string_format(
"num joints: %d total, %d pos ctrl, %d trq ctrl",
graph->nJ, numPosCtrlJoints,
305 linesOut.emplace_back(
string_format(
"ball pos: [% 1.3f,% 1.3f,% 1.3f] m",
306 obs->ele[omLinBall.pos],
307 obs->ele[omLinBall.pos + 1],
308 obs->ele[omLinBall.pos + 2]));
309 linesOut.emplace_back(
string_format(
"club tip pos: [% 1.3f,% 1.3f,% 1.3f] m",
310 obs->ele[omLinBall.pos + 3],
311 obs->ele[omLinBall.pos + 4],
312 obs->ele[omLinBall.pos + 5]));
317 linesOut.emplace_back(
string_format(
"club tip ang: [% 1.3f,% 1.3f,% 1.3f] deg",
318 RCS_RAD2DEG(obs->ele[omAng.pos]),
319 RCS_RAD2DEG(obs->ele[omAng.pos + 1]),
320 RCS_RAD2DEG(obs->ele[omAng.pos + 2])));
325 linesOut.emplace_back(
327 obs->ele[omFT.pos], obs->ele[omFT.pos + 1], obs->ele[omFT.pos + 2]));
330 std::stringstream ss;
332 for (
unsigned int i = 0; i < currentAction->m - 1; i++) {
333 ss << std::fixed << std::setprecision(3) << MatNd_get(currentAction, i, 0) <<
", ";
338 ss << std::fixed << std::setprecision(3) << MatNd_get(currentAction, currentAction->m - 1, 0) <<
"]";
341 if (physicsManager !=
nullptr) {
348 ball_bpi->
material.getDouble(
"slip", ballSlip);
349 double groundSlip = 0;
350 ground_bpi->
material.getDouble(
"slip", groundSlip);
352 linesOut.emplace_back(
354 ball_bpi->
body->m, club_bpi->
body->m));
355 linesOut.emplace_back(
string_format(
"ball friction: %1.3f ground friction: %1.3f",
356 ball_bpi->
material.getFrictionCoefficient(),
357 ground_bpi->
material.getFrictionCoefficient()));
358 linesOut.emplace_back(
string_format(
"ball rolling friction: %1.6f ball slip: %1.5f rad/(Ns)",
359 ball_bpi->
material.getRollingFrictionCoefficient(),
361 linesOut.emplace_back(
string_format(
"ball restitution: %1.3f ground slip: %1.5f rad/(Ns)",
362 ball_bpi->
material.getRestitution(), groundSlip));
virtual bool getProperty(std::string &out, const char *property)=0
virtual bool getPropertyBool(const char *property, bool def=false)=0
void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *obs, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber) override
static ExperimentConfigRegistration< ECMiniGolf > RegMiniGolf("MiniGolf")
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
virtual ActionModel * createActionModel()
BodyParamInfo * getBodyInfo(const char *bodyName)
virtual InitStateSetter * createInitStateSetter()
virtual void initViewer(Rcs::Viewer *viewer)
static OMPartial * fromMask(ObservationModel *wrapped, const std::vector< bool > &mask, bool exclude=false)
std::string string_format(const std::string &format, Args ... args)
ObservationModel * observationModel
Observation model (pluggable) used to create the observation which will be returned from step() ...
PropertySource * properties
Property source (owned)
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
virtual ObservationModel * createObservationModel()
RcsCollisionMdl * collisionMdl
Collision model to use. Is based on the graph, so take care when using with IK etc.
PhysicsMaterial material
Material of the body's first shape.
RcsGraph * graph
Graph description.