46 #include <Rcs_Mat3d.h> 47 #include <Rcs_Vec3d.h> 48 #include <Rcs_typedef.h> 49 #include <Rcs_macros.h> 51 #include <TaskPosition1D.h> 52 #include <TaskVelocity1D.h> 54 #ifdef GRAPHICS_AVAILABLE 56 #include <RcsViewer.h> 72 std::string actionModelType =
"unspecified";
76 std::string taskCombinationMethod =
"unspecified";
80 RcsBody* effector = RcsGraph_getBodyByName(
graph,
"Effector");
83 if (actionModelType ==
"ds_activation") {
89 innerAM->addTask(
new TaskPosition1D(
"X",
graph, effector,
nullptr,
nullptr));
90 innerAM->addTask(
new TaskPosition1D(
"Y",
graph, effector,
nullptr,
nullptr));
93 innerAM->addTask(
new TaskVelocity1D(
"Xd",
graph, effector,
nullptr,
nullptr));
94 innerAM->addTask(
new TaskVelocity1D(
"Yd",
graph, effector,
nullptr,
nullptr));
99 if (taskSpec.empty()) {
100 throw std::invalid_argument(
"No tasks specified!");
102 std::vector<std::unique_ptr<DynamicalSystem>> tasks;
103 for (
auto ts : taskSpec) {
109 std::vector<DynamicalSystem*> taskRel;
110 for (
auto& task : tasks) {
111 taskRel.push_back(task.release());
118 else if (actionModelType ==
"ik_activation") {
121 std::vector<Task*> tasks;
125 RcsBody* goalLL = RcsGraph_getBodyByName(
graph,
"GoalLL");
126 RcsBody* goalUL = RcsGraph_getBodyByName(
graph,
"GoalUL");
127 RcsBody* goalLR = RcsGraph_getBodyByName(
graph,
"GoalLR");
128 RcsBody* goalUR = RcsGraph_getBodyByName(
graph,
"GoalUR");
135 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goalLL,
nullptr));
136 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goalUL,
nullptr));
137 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goalLR,
nullptr));
138 tasks.emplace_back(
new TaskPosition3D(
graph, effector, goalUR,
nullptr));
139 for (
auto task : tasks) {
140 std::stringstream taskName;
141 taskName <<
" Position " << i++ <<
" [m]";
142 task->resetParameter(
143 Task::Parameters(-1.2, 1.2, 1.0, static_cast<std::string>(
"X") + taskName.str()));
145 Task::Parameters(-1.2, 1.2, 1.0, static_cast<std::string>(
"Y") + taskName.str()));
146 task->addParameter(Task::Parameters(0.1, 0.2, 1.0, static_cast<std::string>(
"Z") + taskName.str()));
150 throw std::invalid_argument(
"The combination of velocity-based tasks and AMIKControllerActivation is" 155 for (
auto t : tasks) { amIK->addTask(t); }
159 amIK->setXdesFromTaskSpec(taskSpec);
165 std::ostringstream os;
166 os <<
"Unsupported action model type: " << actionModelType;
167 throw std::invalid_argument(os.str());
194 RcsBody* eff = RcsGraph_getBodyByName(
graph,
"Effector");
201 #ifdef GRAPHICS_AVAILABLE 203 RcsBody* base = RcsGraph_getBodyByName(
graph,
"Effector");
204 double cameraCenter[3];
205 Vec3d_copy(cameraCenter, base->A_BI->org);
208 double cameraLocation[3];
209 cameraLocation[0] = 1.5;
210 cameraLocation[1] = -2.5;
211 cameraLocation[2] = 4.;
215 Vec3d_setUnitVector(cameraUp, 2);
218 viewer->setCameraHomePosition(osg::Vec3d(cameraLocation[0], cameraLocation[1], cameraLocation[2]),
219 osg::Vec3d(cameraCenter[0], cameraCenter[1], cameraCenter[2]),
220 osg::Vec3d(cameraUp[0], cameraUp[1], cameraUp[2]));
226 std::vector<std::string>& linesOut,
229 const MatNd* currentAction,
230 PhysicsBase* simulator,
235 const char* simName =
"None";
236 if (simulator !=
nullptr) {
237 simName = simulator->getClassName();
240 linesOut.emplace_back(
241 string_format(
"physics engine: %s sim time: %2.3f s", simName, currentTime));
245 linesOut.emplace_back(
246 string_format(
"end-eff pos: [% 1.3f,% 1.3f] m end-eff vel: [% 1.2f,% 1.2f] m/s",
247 obs->ele[0], obs->ele[1], obs->ele[sd], obs->ele[sd + 1]));
249 linesOut.emplace_back(
250 string_format(
"actions: [% 1.3f,% 1.3f,% 1.3f,% 1.3f]", currentAction->ele[0], currentAction->ele[1],
251 currentAction->ele[2], currentAction->ele[3]));
253 const double* distForce = forceDisturber->
getLastForce();
254 linesOut.emplace_back(
255 string_format(
"disturbances: [% 3.1f,% 3.1f,% 3.1f] N", distForce[0], distForce[1], distForce[2]));
257 if (physicsManager !=
nullptr) {
260 linesOut.emplace_back(
string_format(
"effector mass: % 1.3f kg", eff_bpi->
body->m));
virtual bool getProperty(std::string &out, const char *property)=0
virtual bool getPropertyBool(const char *property, bool def=false)=0
virtual ActionModel * createActionModel()
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *obs, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber) override
const double * getLastForce() const
static ExperimentConfigRegistration< ECMPblending > RegMPBlending("MPBlending")
static TaskCombinationMethod checkTaskCombinationMethod(std::string tcmName)
virtual InitStateSetter * createInitStateSetter()
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
virtual void initViewer(Rcs::Viewer *viewer)
virtual const std::vector< PropertySource * > & getChildList(const char *prefix)=0
virtual unsigned int getStateDim() const =0
virtual ForceDisturber * createForceDisturber()
BodyParamInfo * getBodyInfo(const char *bodyName)
static DynamicalSystem * create(PropertySource *properties, unsigned int innerTaskDim)
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 ObservationModel * createObservationModel()
RcsGraph * graph
Graph description.