1.新建环境
新建Webots目录,wizards -> New Project Directory…
新建世界,File -> New World
在左边场景树依次添加下面内容:
1.TexturedBackground/background
2.rectanglearea
3.robots (PROTO (Webots) / robots / gctronic / e-puck / E-puck (Robot))
添加完毕,保存
note:
SHIFT + left-click + drag to move the robot parallel to the floor;
SHIFT + mouse-wheel to move the robot up or down.
2.新建控制器
创建控制器文件(这里用C),命名为 e-puck_go_forward (Wizards -> New Robot Controller…)
把e-puck_go_forward与机器人e-puck关联:
在左边场景树中找到e-puck的节点,双击"controller开头文字",在下拉框中选择新建好的控制器文件。
#include <webots/robot.h>
#include <webots/motor.h>
#define TIME_STEP 64
#define MAX_SPEED 6.28
int main(int argc, char **argv)
{
wb_robot_init();
// get a handler to the motors and set target position to infinity (speed control)
WbDeviceTag left_motor = wb_robot_get_device("left wheel motor");
WbDeviceTag right_motor = wb_robot_get_device("right wheel motor");
//wb_motor_set_position(left_motor, INFINITY);
//wb_motor_set_position(right_motor, INFINITY);
wb_motor_set_position(left_motor, 5);
wb_motor_set_position(right_motor, 5);
// 第一个参数是电机名,第二个是旋转弧度
// set up the motor speeds at 10% of the MAX_SPEED.
//wb_motor_set_velocity(left_motor, 0.1 * MAX_SPEED);
//wb_motor_set_velocity(right_motor, 0.1 * MAX_SPEED);
while (wb_robot_step(TIME_STEP) != -1) {
}
wb_robot_cleanup();
return 0;
}
3.总结
Webots世界由各种节点组成(类似VRML97树状结构),包括地板、背景、机器人等。世界的后缀为.wb。控制器控制机器人运动,可以用各种常用语言编写,再关联到机器人上即可。