| Prev: Wheeled robots | Up: Using robots | Next: Programming a fitness function |
|---|---|---|
Table of contents
Unlike the other robots (i.e. the Khepera, ePuck, and MarxBot), the iCub robot model is included in the iCub plugin that should be compiled and istalled separately from FARSA and loaded at runtime together with the plugin of your experiment (see the documentation on FARSA istallation).
This also implies that you should declare that your experimental plugin depends on the iCub plugin by adding the following instruction after the ADD_FARSAPLUGIN command in the CMakeLists.txt file of your plugin (the string "MyPlugin" in the example below should be replaced with the name of your experimental plugin). The addition of this instruction allows you to include the headers with iCub-related code in the source code of your experimental plugin. Moreover, it ensures that the iCub plugin will be loaded automatically when your experimental plugin is loaded.
:::CMake
FARSA_PLUGIN_DEPENDENCIES(MyPlugin iCub)
Below we include a portion of the iCubShowcase plugin example that illustrates how you can create, initialize and control a simulated iCub robot. More specifically the createiCub() function istantiates an iCub robot (an instance of the PhyiCub class), initializes the posture of the robot, and enables the motors of the torso. The simulationStep() function shows how to set and access the velocity of one of the iCub joint.
:::C++
void iCubShowcase::createiCub()
{
// world is a resource (even if we don't access it via getResource(), here), so we must
// take the lock
ResourcesLocker resourceLocker(this);
// Creating the iCub. Here we set the initial position and do not create the controlboards
// (that are needed only if communication with YARP is required)
farsa::wMatrix mtr = farsa::wMatrix::identity();
mtr.w_pos.z = 0.1;
m_icub = new farsa::PhyiCub(m_world, "icub", mtr, false);
// Blocking a piece of the iCub torso so that it always remains in the same position in the
// world
m_icub->blockTorso0(true);
// Setting a posture. This simply moves all joints to the desired positions. It should
// not be used while iCub joints are moved by the motor controller
QMap<int, real> jointSetup;
jointSetup[farsa::PhyiCub::right_shoulder_pitch] = 0.0;
jointSetup[farsa::PhyiCub::right_shoulder_roll] = 90.0;
jointSetup[farsa::PhyiCub::right_shoulder_yaw] = 0.0;
jointSetup[farsa::PhyiCub::right_elbow] = 90.0;
jointSetup[farsa::PhyiCub::right_wrist_prosup] = 0.0;
jointSetup[farsa::PhyiCub::right_wrist_pitch] = 0.0;
jointSetup[farsa::PhyiCub::right_wrist_yaw] = 0.0;
jointSetup[farsa::PhyiCub::left_shoulder_pitch] = 0.0;
jointSetup[farsa::PhyiCub::left_shoulder_roll] = 90.0;
jointSetup[farsa::PhyiCub::left_shoulder_yaw] = 0.0;
jointSetup[farsa::PhyiCub::left_elbow] = 90.0;
jointSetup[farsa::PhyiCub::left_wrist_prosup] = 0.0;
jointSetup[farsa::PhyiCub::left_wrist_pitch] = 0.0;
jointSetup[farsa::PhyiCub::left_wrist_yaw] = 0.0;
m_icub->configurePosture(jointSetup);
// Enabling torso motors
m_icub->torsoController()->setEnabled(true);
}
void iCubShowcase::simulationStep(int step)
{
// world is a resource (even if we don't access it via getResource(), here), so we must
// take the lock
ResourcesLocker resourceLocker(this);
// Moving torso. We invert velocity every 200 steps
if ((step % 200) == 0) {
m_torso0Vel *= -1.0;
}
m_icub->torsoController()->velocityMove(0, m_torso0Vel);
m_world->advance();
// Reading torso position
double pos;
m_icub->torsoController()->getEncoder(0, &pos);
Logger::info(QString("Torso position in degrees: %1").arg(pos));
}
If your experimental plugin is based on the EvoRobotExperiment class, the iCub robot will be automatically istantiated. The robot can be accessed and configured by using the agent[0]:robot resource, as for wheeled robots (see wheeled robots). This is possible because the iCub plugin provides a component named iCubRobot that can be used as the type of the [ROBOT] subgroup.
Manual: CustomizingRobots
Manual: Home
Manual: Installation
Manual: ProgrammingFitnessFunction
Manual: WheeledRobots
Anonymous