Webots学习笔记 1.创建自己的仿真机器人模型

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。控制器控制机器人运动,可以用各种常用语言编写,再关联到机器人上即可。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值