56 #include <Rcs_Mat3d.h> 57 #include <Rcs_Vec3d.h> 58 #include <Rcs_typedef.h> 59 #include <Rcs_macros.h> 60 #include <TaskPosition1D.h> 61 #include <TaskVelocity1D.h> 62 #include <TaskDistance.h> 64 #ifdef GRAPHICS_AVAILABLE 66 #include <RcsViewer.h> 82 std::string actionModelType =
"unspecified";
86 RcsBody* effector = RcsGraph_getBodyByName(
graph,
"Effector");
89 if (actionModelType ==
"joint_pos") {
93 else if (actionModelType ==
"joint_vel") {
94 double max_action = 90*M_PI/180;
98 else if (actionModelType ==
"joint_acc") {
99 double max_action = RCS_DEG2RAD(120);
103 else if (actionModelType ==
"ik") {
107 throw std::invalid_argument(
"Position tasks are not implemented for AMIKGeneric in this environment.");
110 amIK->addTask(
new TaskVelocity1D(
"Xd",
graph, effector,
nullptr,
nullptr));
111 amIK->addTask(
new TaskVelocity1D(
"Zd",
graph, effector,
nullptr,
nullptr));
116 else if (actionModelType ==
"ik_activation") {
118 std::string taskCombinationMethod =
"unspecified";
124 std::vector<Task*> tasks;
129 RcsBody* goal1 = RcsGraph_getBodyByName(
graph,
"Goal1");
130 RcsBody* goal2 = RcsGraph_getBodyByName(
graph,
"Goal2");
131 RcsBody* goal3 = RcsGraph_getBodyByName(
graph,
"Goal3");
145 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goal1,
nullptr));
146 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goal2,
nullptr));
147 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goal3,
nullptr));
148 for (
auto task : tasks) {
149 std::stringstream taskName;
150 taskName <<
" Position " << i++ <<
" [m]";
151 task->resetParameter(
152 Task::Parameters(-0.9, 0.9, 1.0,
"X" + taskName.str()));
154 Task::Parameters(-0.01, 0.01, 1.0,
"Y" + taskName.str()));
155 task->addParameter(Task::Parameters(0., 1.4, 1.0,
"Z" + taskName.str()));
159 throw std::invalid_argument(
"Velocity tasks are not supported for AMIKControllerActivation.");
163 for (
auto t : tasks) { amIK->addTask(t); }
167 amIK->setXdesFromTaskSpec(taskSpec);
172 std::cout <<
"IK considers the provided collision model" << std::endl;
180 else if (actionModelType ==
"ds_activation") {
186 innerAM->addTask(
new TaskPosition1D(
"X",
graph, effector,
nullptr,
nullptr));
187 innerAM->addTask(
new TaskPosition1D(
"Z",
graph, effector,
nullptr,
nullptr));
190 innerAM->addTask(
new TaskVelocity1D(
"Xd",
graph, effector,
nullptr,
nullptr));
191 innerAM->addTask(
new TaskVelocity1D(
"Zd",
graph, effector,
nullptr,
nullptr));
196 std::vector<std::unique_ptr<DynamicalSystem>> tasks;
197 for (
auto ts : taskSpec) {
202 throw std::invalid_argument(
"No tasks specified!");
208 std::cout <<
"IK considers the provided collision model" << std::endl;
214 std::vector<DynamicalSystem*> taskRel;
215 for (
auto& task : tasks) {
216 taskRel.push_back(task.release());
220 std::string taskCombinationMethod =
"unspecified";
229 std::ostringstream os;
230 os <<
"Unsupported action model type: " << actionModelType;
231 throw std::invalid_argument(os.str());
242 omLin->setMinState(-1.7);
243 omLin->setMaxState(1.7);
244 omLin->setMaxVelocity(5.0);
249 omLin->setMinState(-1.7);
250 omLin->setMaxState(1.7);
256 RcsSensor* fts = RcsGraph_getSensorByName(
graph,
"EffectorLoadCell");
259 fullState->addPart(
OMPartial::fromMask(omForceTorque, {
true,
false,
true,
false,
false,
false}));
267 fullState->addPart(omColl);
277 fullState->addPart(omCollisionCost);
296 throw std::invalid_argument(
"The action model needs to be of type ActionModelIK!");
300 std::string actionModelType =
"unspecified";
302 bool haveJointPos = actionModelType ==
"joint_pos";
308 else if (actionModelType ==
"ds_activation") {
314 fullState->addPart(omGoalDist);
318 std::ostringstream os;
319 os <<
"The action model needs to be of type AMDynamicalSystemActivation but is: " << castedAM;
320 throw std::invalid_argument(os.str());
329 fullState->addPart(omDescr);
333 std::ostringstream os;
334 os <<
"The action model needs to be of type AMDynamicalSystemActivation but is: " << castedAM;
335 throw std::invalid_argument(os.str());
357 RcsBody* link3 = RcsGraph_getBodyByName(
graph,
"Link3");
367 #ifdef GRAPHICS_AVAILABLE 369 RcsBody* base = RcsGraph_getBodyByName(
graph,
"Base");
370 double cameraCenter[3];
371 Vec3d_copy(cameraCenter, base->A_BI->org);
372 cameraCenter[1] -= 0.5;
373 cameraCenter[2] += 0.3;
376 double cameraLocation[3];
377 cameraLocation[0] = 0.;
378 cameraLocation[1] = 4.;
379 cameraLocation[2] = 2.5;
383 Vec3d_setUnitVector(cameraUp, 2);
386 viewer->setCameraHomePosition(osg::Vec3d(cameraLocation[0], cameraLocation[1], cameraLocation[2]),
387 osg::Vec3d(cameraCenter[0], cameraCenter[1], cameraCenter[2]),
388 osg::Vec3d(cameraUp[0], cameraUp[1], cameraUp[2]));
394 std::vector<std::string>& linesOut,
397 const MatNd* currentAction,
398 PhysicsBase* simulator,
403 const char* simName =
"None";
404 if (simulator !=
nullptr) {
405 simName = simulator->getClassName();
408 linesOut.emplace_back(
409 string_format(
"physics engine: %s sim time: %2.3f s", simName, currentTime));
411 unsigned int numPosCtrlJoints = 0;
412 unsigned int numTrqCtrlJoints = 0;
414 RCSGRAPH_TRAVERSE_JOINTS(
graph) {
415 if (JNT->jacobiIndex != -1) {
416 if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_POSITION) {
419 else if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_TORQUE) {
424 linesOut.emplace_back(
425 string_format(
"num joints: %d total, %d pos ctrl, %d trq ctrl",
graph->nJ, numPosCtrlJoints,
433 linesOut.emplace_back(
434 string_format(
"end-eff pos: [% 1.3f,% 1.3f] m end-eff vel: [% 1.2f,% 1.2f] m/s",
435 obs->ele[omLin.pos], obs->ele[omLin.pos + 1],
436 obs->ele[sd + omLin.vel], obs->ele[sd + omLin.vel + 1]));
439 linesOut.emplace_back(
441 obs->ele[omLinPos.pos], obs->ele[omLinPos.pos + 1]));
446 linesOut.emplace_back(
448 obs->ele[omGD.pos + 0], obs->ele[omGD.pos + 1], obs->ele[omGD.pos + 2]));
453 linesOut.emplace_back(
454 string_format(
"forces: [% 3.1f,% 3.1f] N", obs->ele[omFT.pos + 0], obs->ele[omFT.pos + 1]));
457 if (forceDisturber) {
458 const double* distForce = forceDisturber->
getLastForce();
459 linesOut.emplace_back(
460 string_format(
"disturbances: [% 3.1f,% 3.1f,% 3.1f] N", distForce[0], distForce[1], distForce[2]));
463 linesOut.emplace_back(
465 currentAction->ele[0], currentAction->ele[1], currentAction->ele[2]));
467 if (physicsManager !=
nullptr) {
473 linesOut.emplace_back(
475 link3_bpi->
body->m));
480 linesOut.emplace_back(
string_format(
"manipulability: % 5.3f", obs->ele[omManip.pos + 0]));
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< ECPlanar3Link > RegPlanar3Link("Planar3Link")
virtual PropertySource * getChild(const char *prefix)=0
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
const double * getLastForce() const
static TaskCombinationMethod checkTaskCombinationMethod(std::string tcmName)
static ObservationModel * observeUnconstrainedJoints(RcsGraph *graph)
virtual const std::vector< PropertySource * > & getChildList(const char *prefix)=0
virtual unsigned int getStateDim() const =0
BodyParamInfo * getBodyInfo(const char *bodyName)
virtual ForceDisturber * createForceDisturber()
static DynamicalSystem * create(PropertySource *properties, unsigned int innerTaskDim)
virtual void initViewer(Rcs::Viewer *viewer)
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
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)
const AM * unwrap() const
virtual ObservationModel * createObservationModel()
virtual ActionModel * createActionModel()
ActionModel * actionModel
Action model (pluggable)
RcsCollisionMdl * collisionMdl
Collision model to use. Is based on the graph, so take care when using with IK etc.
RcsGraph * graph
Graph description.
virtual InitStateSetter * createInitStateSetter()