50 #include <Rcs_macros.h> 51 #include <Rcs_typedef.h> 52 #include <Rcs_Mat3d.h> 53 #include <Rcs_Vec3d.h> 55 #ifdef GRAPHICS_AVAILABLE 57 #include <RcsViewer.h> 74 std::string actionModelType =
"unspecified";
77 if (actionModelType ==
"joint_pos") {
81 else if (actionModelType ==
"joint_acc") {
82 double maxAction = RCS_DEG2RAD(120);
87 else if (actionModelType ==
"plate_angpos") {
91 else if (actionModelType ==
"plate_angvel") {
92 double maxAction = RCS_DEG2RAD(120);
97 else if (actionModelType ==
"plate_angacc") {
98 double maxAction = RCS_DEG2RAD(120);
103 else if (actionModelType ==
"plate_acc5d") {
105 MatNd_fromStack(maxAction, 5, 1);
107 double max_lin = 0.5;
108 double max_ang = RCS_DEG2RAD(120);
110 maxAction->ele[0] = max_lin;
111 maxAction->ele[1] = max_lin;
112 maxAction->ele[2] = max_lin;
113 maxAction->ele[3] = max_ang;
114 maxAction->ele[4] = max_ang;
120 std::ostringstream os;
121 os <<
"Unsupported action model type: " << actionModelType;
122 throw std::invalid_argument(os.str());
128 RcsBody* plate = RcsGraph_getBodyByName(
graph,
"Plate");
129 RcsBody* plateOrigMarker = RcsGraph_getBodyByName(
graph,
"PlateOriginMarker");
130 RCHECK_MSG(plateOrigMarker,
"PlateOriginMarker is missing, please update your xml.");
132 HTr_copyOrRecreate(&plateOrigMarker->A_BP, plate->A_BI);
139 std::string actionModelType =
"joint_pos";
141 bool havePlateLinPos = actionModelType ==
"plate_acc5d";
146 if (havePlateLinPos) {
148 plin->setMinState(-0.1);
149 plin->setMaxState(0.1);
150 plin->setMaxVelocity(2.0);
151 fullState->addPart(plin);
156 pang->setMinState(-45*M_PI/180);
157 pang->setMaxState(45*M_PI/180);
158 pang->setMaxVelocity(2*360*M_PI/180);
165 if (ballObsAngular) {
187 RcsBody* ball = RcsGraph_getBodyByName(
graph,
"Ball");
188 RcsBody* plate = RcsGraph_getBodyByName(
graph,
"Plate");
194 initManipulability = 0;
198 initManipulability = amIK->
getController()->computeManipulabilityCost();
201 #ifdef GRAPHICS_AVAILABLE 203 RcsBody* plate = RcsGraph_getBodyByName(
graph,
"Plate");
205 std::string cameraView =
"side";
209 double cameraCenter[3];
210 Vec3d_copy(cameraCenter, plate->A_BI->org);
213 double cameraLocation[3];
214 Vec3d_setZero(cameraLocation);
218 Vec3d_setUnitVector(cameraUp, 2);
220 if (cameraView ==
"topdown") {
222 Vec3d_copy(cameraLocation, cameraCenter);
224 double cameraToPlateDistanceZ = 1.6;
226 cameraLocation[2] += cameraToPlateDistanceZ;
228 Vec3d_setUnitVector(cameraUp, 1);
229 Vec3d_transRotateSelf(cameraUp, plate->A_BI->rot);
232 else if (cameraView ==
"side") {
234 cameraCenter[2] -= 0.4;
236 cameraLocation[0] = 2.9;
237 cameraLocation[2] = 1.3;
240 Vec3d_transformSelf(cameraLocation, plate->A_BI);
244 RMSG(
"Unsupported camera view: %s", cameraView.c_str());
249 viewer->setCameraHomePosition(osg::Vec3d(cameraLocation[0], cameraLocation[1], cameraLocation[2]),
250 osg::Vec3d(cameraCenter[0], cameraCenter[1], cameraCenter[2]),
251 osg::Vec3d(cameraUp[0], cameraUp[1], cameraUp[2]));
256 std::vector<std::string>& linesOut,
double currentTime,
const MatNd* obs,
const MatNd* currentAction,
260 const char* simName =
"None";
261 if (simulator != NULL) {
262 simName = simulator->getClassName();
266 "physics engine: %s simulation time: %2.3f s",
267 simName, currentTime));
269 unsigned int numPosCtrlJoints = 0;
270 unsigned int numTrqCtrlJoints = 0;
272 RCSGRAPH_TRAVERSE_JOINTS(
graph) {
273 if (JNT->jacobiIndex != -1) {
274 if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_POSITION) {
277 else if (JNT->ctrlType == RCSJOINT_CTRL_TYPE::RCSJOINT_CTRL_TORQUE) {
282 linesOut.emplace_back(
283 string_format(
"num joints: %d total, %d pos ctrl, %d trq ctrl",
graph->nJ, numPosCtrlJoints,
287 "plate angles: [% 3.2f,% 3.2f] deg",
288 RCS_RAD2DEG(obs->ele[0]), RCS_RAD2DEG(obs->ele[1])));
290 const double* distForce = forceDisturber->
getLastForce();
292 "disturbances: [% 3.1f,% 3.1f,% 3.1f] N",
293 distForce[0], distForce[1], distForce[2]));
295 if (physicsManager != NULL) {
298 double* com = ball_bpi->
body->Inertia->org;
299 double ball_radius = ball_bpi->
body->shape[0]->extents[0];
301 ball_bpi->
material.getDouble(
"slip", slip);
304 "ball mass: %2.2f kg ball radius: %2.3f cm",
305 ball_bpi->
body->m, ball_radius*100));
308 "ball friction: %1.2f ball rolling friction: %1.3f",
309 ball_bpi->
material.getFrictionCoefficient(),
310 ball_bpi->
material.getRollingFrictionCoefficient()/ball_radius));
313 "ball slip: %3.1f rad/(Ns) CoM offset:[% 2.1f, % 2.1f, % 2.1f] mm",
314 slip, com[0]*1000, com[1]*1000, com[2]*1000));
322 "manipulability: %10.8f ",
virtual bool getProperty(std::string &out, const char *property)=0
virtual bool getPropertyBool(const char *property, bool def=false)=0
virtual InitStateSetter * createInitStateSetter()
double initManipulability
void getHUDText(std::vector< std::string > &linesOut, double currentTime, const MatNd *obs, const MatNd *currentAction, PhysicsBase *simulator, PhysicsParameterManager *physicsManager, ForceDisturber *forceDisturber) override
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
const double * getLastForce() const
virtual ActionModel * createActionModel()
virtual ObservationModel * createObservationModel()
virtual void initViewer(Rcs::Viewer *viewer)
virtual void populatePhysicsParameters(PhysicsParameterManager *manager)
BodyParamInfo * getBodyInfo(const char *bodyName)
static ExperimentConfigRegistration< ECBallOnPlate > RegBallOnPlate("BallOnPlate")
virtual ForceDisturber * createForceDisturber()
static OMPartial * fromMask(ObservationModel *wrapped, const std::vector< bool > &mask, bool exclude=false)
std::string string_format(const std::string &format, Args ... args)
PropertySource * properties
Property source (owned)
const AM * unwrap() const
const ControllerBase * getController() const
ActionModel * actionModel
Action model (pluggable)
PhysicsMaterial material
Material of the body's first shape.
RcsGraph * graph
Graph description.