Diferencia entre revisiones de «OpenMR: Servocontroller examples»
De WikiRobotics
(→Test-servocontroller-1: Set the position of one servo) |
(→Test-servocontroller-1: Set the position of one servo) |
||
Línea 2: | Línea 2: | ||
== Test-servocontroller-1: Set the position of one servo == | == Test-servocontroller-1: Set the position of one servo == | ||
+ | |||
+ | Example of the '''setpos1''' command to set the position of the servo 0. The module's angle is set to 45 and -45 degrees alternatively. | ||
{| | {| | ||
Línea 8: | Línea 10: | ||
|} | |} | ||
− | + | In the begining the environmnet is created (loaded from the file ''models/Unimod1.env.xml'') and the camera view is set. The environment consist of one robot with only one module (Unimod). | |
− | |||
− | In the begining the environmnet is created (loaded from the file models/Unimod1.env.xml) and the camera view is set. The environment consist of one robot with only one module (Unimod). | ||
− | First the pointer to the robot is obtained from the environment ('''penv'''). In a general scence, there can be multiple robots. But in this example there is only one robot (robot number 0): | + | First the pointer to the robot('''probot''') is obtained from the environment ('''penv'''). In a general scence, there can be multiple robots. But in this example there is only one robot (robot number 0): |
std::vector<RobotBasePtr> robots; | std::vector<RobotBasePtr> robots; | ||
penv->GetRobots(robots); | penv->GetRobots(robots); | ||
RobotBasePtr probot = robots[0]; | RobotBasePtr probot = robots[0]; | ||
+ | |||
+ | Then the '''servocontroller''' is set as the robot controller: | ||
+ | |||
+ | ControllerBasePtr pcontroller = penv->CreateController("servocontroller"); | ||
+ | probot->SetController(pcontroller,""); | ||
+ | |||
+ | In the main loop, the serpos1 command is used to set the module's angle: | ||
+ | |||
+ | while(1) { | ||
+ | is << "setpos1 0 45 "; | ||
+ | pcontroller->SendCommand(os,is); | ||
+ | sleep(1); | ||
+ | |||
+ | is << "setpos1 0 -45 "; | ||
+ | pcontroller->SendCommand(os,is); | ||
+ | sleep(1); | ||
+ | } | ||
== Example 2: Set the position of two servos == | == Example 2: Set the position of two servos == |
Revisión del 03:51 7 jul 2010
Contenido
Introduction
Test-servocontroller-1: Set the position of one servo
Example of the setpos1 command to set the position of the servo 0. The module's angle is set to 45 and -45 degrees alternatively.
In the begining the environmnet is created (loaded from the file models/Unimod1.env.xml) and the camera view is set. The environment consist of one robot with only one module (Unimod).
First the pointer to the robot(probot) is obtained from the environment (penv). In a general scence, there can be multiple robots. But in this example there is only one robot (robot number 0):
std::vector<RobotBasePtr> robots; penv->GetRobots(robots); RobotBasePtr probot = robots[0];
Then the servocontroller is set as the robot controller:
ControllerBasePtr pcontroller = penv->CreateController("servocontroller"); probot->SetController(pcontroller,"");
In the main loop, the serpos1 command is used to set the module's angle:
while(1) { is << "setpos1 0 45 "; pcontroller->SendCommand(os,is); sleep(1); is << "setpos1 0 -45 "; pcontroller->SendCommand(os,is); sleep(1); }