Wiki

Clone wiki

scl-manips-v2 / howdoi / graphics_dyn_diff

Robot specs for graphics and physics are independent (but usually identical)

By default, in most applications and tutorials, the parser code usually uses the same robot specification in the graphics and physics modules.

However, you might want to change this behavior. Say, to do a study that tests human reactions to a simulated scene where the physics decides the motion but the graphics displays some other information. eg., Run physics on a robot that is 6 feet tall, but display a robot with exactly the same rigid bodies and joint angles, except that the displayed robot has arms that are 25% shorter..

Specifying different graphics and physics for the same robot

Check your xml file

The first thing to do is understand what is read in from the file specification. Some simple example code is in tutorial 1 (scl.git/tutorials/) .

66: bool flag = p.readRobotFromFile("./RRRCfg.xml","rrrbot",rds);
74:  scl_util::printRobotLinkTree(*(rds.rb_tree_.getRootNode()),0);

Note that the robot configuration is read into rds, a data structure. SCL primarily works with data structures like this.

Now run the tutorial and see that it prints out the robot spec. You should see the parsed link lengths for the robot:

 Link: link_0 Robot: <rrrbot> Parent: <root>, Id: 0, Depth: 1, Com:    0    0 -0.1, Mass: 1, Inertia: 
1 0 0
0 1 0
0 0 1,
Pos in par: 0 0 0,
Ori in par: 
1 0 0
0 1 0
0 0 1

Change the xml file and this will change. This should convince you that your xml spec is parsed properly.

Understand the relationship between the parsed data and code modules

In case you want different graphics and dynamics specifications, note the initialization for both (in tutorial 3):

86  bool flag = p.readRobotFromFile("./RRRRCfg.xml","rrrrbot",rds);
87  flag = flag && rgcm.init(rds);            //Simple way to set up dynamic tree...
88  flag = flag && dyn_tao.init(rds);         //Set up integrator object

As before, this reads in the spec into a data structure called "rds", and then initializes the data structure, and then initializes the dynamics/physics with the "rds" data structure.

A few lines later, you'll see that the same "rds" is added to the graphics:

98  flag = flag && rchai.addRobotToRender(&rds,&rio);

You can read in a different "rds" from a different xml file. Say:

98  bool flag = p.readRobotFromFile("./RRRRCfg-WithDifferentLinkLengths.xml","rrrrbot",rds-links-modified);
99  flag = flag && rchai.addRobotToRender(&rds-links-modified,&rio);

This means that the dynamics still have the older specification, but the graphics will display the newer specification.

However, note that the robot-io data structure ("rio") is the same, so the new robot's joints will move just like the old robot, only that they will have different lengths. *

Updated