55 #include <Rcs_Mat3d.h> 56 #include <Rcs_Vec3d.h> 57 #include <Rcs_typedef.h> 58 #include <Rcs_macros.h> 59 #include <TaskVelocity1D.h> 60 #include <TaskOmega1D.h> 62 #ifdef GRAPHICS_AVAILABLE 64 #include <RcsViewer.h> 81 std::string actionModelType =
"unspecified";
85 std::string taskCombinationMethod =
"unspecified";
90 RcsBody* effector = RcsGraph_getBodyByName(
graph,
"Effector");
93 if (actionModelType ==
"ik_activation") {
96 std::vector<Task*> tasks;
100 throw std::invalid_argument(
"Position tasks based are not implemented for PlanarInsert!");
103 tasks.emplace_back(
new TaskVelocity1D(
"Xd",
graph, effector,
nullptr,
nullptr));
104 tasks.emplace_back(
new TaskVelocity1D(
"Zd",
graph, effector,
nullptr,
nullptr));
105 tasks.emplace_back(
new TaskOmega1D(
"Bd",
graph, effector,
nullptr,
nullptr));
106 tasks[0]->resetParameter(Task::Parameters(-0.5, 0.5, 1.0,
"X Velocity [m/s]"));
107 tasks[1]->resetParameter(Task::Parameters(-0.5, 0.5, 1.0,
"Z Velocity [m/s]"));
111 for (
auto t : tasks) { amIK->addTask(t); }
115 amIK->setXdesFromTaskSpec(taskSpec);
120 std::cout <<
"IK considers the provided collision model" << std::endl;
128 else if (actionModelType ==
"ds_activation") {
131 innerAM->addTask(
new TaskVelocity1D(
"Xd",
graph, effector,
nullptr,
nullptr));
132 innerAM->addTask(
new TaskVelocity1D(
"Zd",
graph, effector,
nullptr,
nullptr));
133 innerAM->addTask(
new TaskOmega1D(
"Bd",
graph, effector,
nullptr,
nullptr));
137 std::vector<unsigned int> offsets{0, 0, 1, 1, 2, 2};
138 std::vector<std::unique_ptr<DynamicalSystem>> tasks;
140 for (
auto tsk : taskSpec) {
143 tasks.emplace_back(
new DSSlice(ds, offsets[i], 1));
147 throw std::invalid_argument(
"No tasks specified!");
153 std::cout <<
"IK considers the provided collision model" << std::endl;
159 std::vector<DynamicalSystem*> taskRel;
160 for (
auto& task : tasks) {
161 taskRel.push_back(task.release());
169 std::ostringstream os;
170 os <<
"Unsupported action model type: " << actionModelType;
171 throw std::invalid_argument(os.str());
181 omLin->setMinState(-1.7);
182 omLin->setMaxState(1.7);
183 omLin->setMaxVelocity(5.);
187 omAng->setMaxVelocity(20.);
190 std::string actionModelType =
"unspecified";
192 if (actionModelType ==
"ds_activation") {
198 fullState->addPart(omGoalDist);
202 std::ostringstream os;
203 os <<
"The action model needs to be of type AMDynamicalSystemActivation but is: " << castedAM;
204 throw std::invalid_argument(os.str());
213 fullState->addPart(omDescr);
217 std::ostringstream os;
218 os <<
"The action model needs to be of type AMDynamicalSystemActivation but is: " << castedAM;
219 throw std::invalid_argument(os.str());
226 RcsSensor* fts = RcsGraph_getSensorByName(
graph,
"EffectorLoadCell");
229 fullState->addPart(
OMPartial::fromMask(omForceTorque, {
true,
false,
true,
false,
false,
false}));
237 fullState->addPart(omColl);
247 fullState->addPart(omCollisionCost);
266 throw std::invalid_argument(
"The action model needs to be of type ActionModelIK!");
291 RcsBody* effector = RcsGraph_getBodyByName(
graph,
"Effector");
298 #ifdef GRAPHICS_AVAILABLE 300 RcsBody* base = RcsGraph_getBodyByName(
graph,
"Base");
301 double cameraCenter[3];
302 Vec3d_copy(cameraCenter, base->A_BI->org);
303 cameraCenter[1] -= 0.5;
304 cameraCenter[2] += 0.3;
307 double cameraLocation[3];
308 cameraLocation[0] = 0.;
309 cameraLocation[1] = 4.;
310 cameraLocation[2] = 2.5;
314 Vec3d_setUnitVector(cameraUp, 2);
317 viewer->setCameraHomePosition(osg::Vec3d(cameraLocation[0], cameraLocation[1], cameraLocation[2]),
318 osg::Vec3d(cameraCenter[0], cameraCenter[1], cameraCenter[2]),
319 osg::Vec3d(cameraUp[0], cameraUp[1], cameraUp[2]));
325 std::vector<std::string>& linesOut,
double currentTime,
const MatNd* obs,
const MatNd* currentAction,
329 const char* simName =
"None";
330 if (simulator !=
nullptr) {
331 simName = simulator->getClassName();
334 linesOut.emplace_back(
335 string_format(
"physics engine: %s sim time: %2.3f s", simName, currentTime));
337 unsigned int numPosCtrlJoints = 0;
338 unsigned int numTrqCtrlJoints = 0;
340 RCSGRAPH_TRAVERSE_JOINTS(
graph) {
341 if (JNT->jacobiIndex != -1) {
342 if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_POSITION) {
345 else if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_TORQUE) {
350 linesOut.emplace_back(
351 string_format(
"num joints: %d total, %d pos ctrl, %d trq ctrl",
graph->nJ, numPosCtrlJoints,
358 if (omLin && omAng) {
360 linesOut.emplace_back(
string_format(
"end-eff pos: [% 1.3f,% 1.3f,% 1.3f] m, m, deg",
361 obs->ele[omLin.pos], obs->ele[omLin.pos + 1],
362 RCS_RAD2DEG(obs->ele[omAng.pos])));
364 linesOut.emplace_back(
string_format(
"end-eff vel: [% 1.3f,% 1.3f,% 1.3f] m/s, m/s, deg/s",
365 obs->ele[sd + omLin.vel],
366 obs->ele[sd + omLin.vel + 1],
367 RCS_RAD2DEG(obs->ele[sd + omAng.vel])));
372 linesOut.emplace_back(
373 string_format(
"forces: [% 3.1f,% 3.1f] N", obs->ele[omFT.pos], obs->ele[omFT.pos + 1]));
378 linesOut.emplace_back(
379 string_format(
"ts delta: [% 1.3f,% 1.3f] m", obs->ele[omTSD.pos], obs->ele[omTSD.pos + 1]));
382 std::stringstream ss;
384 for (
unsigned int i = 0; i < currentAction->m - 1; i++) {
385 ss << std::fixed << std::setprecision(3) << MatNd_get(currentAction, i, 0) <<
", ";
390 ss << std::fixed << std::setprecision(3) << MatNd_get(currentAction, currentAction->m - 1, 0) <<
"]";
395 std::stringstream ss;
396 ss <<
"activations: [";
397 for (
unsigned int i = 0; i < castedAM->getDim() - 1; i++) {
398 ss << std::fixed << std::setprecision(3) << MatNd_get(castedAM->getActivation(), i, 0) <<
", ";
403 ss << std::fixed << std::setprecision(3) <<
404 MatNd_get(castedAM->getActivation(), castedAM->getDim() - 1, 0) <<
"]";
407 linesOut.emplace_back(
string_format(
"tcm: %s", castedAM->getTaskCombinationMethodName()));
410 if (forceDisturber) {
411 const double* distForce = forceDisturber->
getLastForce();
412 linesOut.emplace_back(
413 string_format(
"disturbances: [% 3.1f,% 3.1f,% 3.1f] N", distForce[0], distForce[1], distForce[2]));
416 if (physicsManager !=
nullptr) {
426 linesOut.emplace_back(
427 string_format(
"link masses: [%1.2f, %1.2f, %1.2f, %1.2f] kg wall Z pos: %1.3f m",
428 link1_bpi->
body->m, link2_bpi->
body->m, link3_bpi->
body->m, link4_bpi->
body->m,
429 uWall_bpi->
body->A_BP->org[2]));
430 linesOut.emplace_back(
string_format(
"wall friction: [%1.3f, %1.3f] l/u effector friction: %1.3f",
431 lWall_bpi->
material.getFrictionCoefficient(),
432 uWall_bpi->
material.getFrictionCoefficient(),
433 eff_bpi->
material.getFrictionCoefficient()));
virtual bool getProperty(std::string &out, const char *property)=0
virtual ObservationModel * createObservationModel()
virtual bool getPropertyBool(const char *property, bool def=false)=0
virtual ActionModel * createActionModel()
virtual PropertySource * getChild(const char *prefix)=0
virtual void initViewer(Rcs::Viewer *viewer)
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
const double * getLastForce() const
static TaskCombinationMethod checkTaskCombinationMethod(std::string tcmName)
virtual InitStateSetter * createInitStateSetter()
virtual const std::vector< PropertySource * > & getChildList(const char *prefix)=0
virtual unsigned int getStateDim() const =0
BodyParamInfo * getBodyInfo(const char *bodyName)
static DynamicalSystem * create(PropertySource *properties, unsigned int innerTaskDim)
virtual ForceDisturber * createForceDisturber()
void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *obs, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber) override
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)
static ExperimentConfigRegistration< ECPlanarInsert > RegPlanarInsert("PlanarInsert")
const AM * unwrap() const
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
ActionModel * actionModel
Action model (pluggable)
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.