第二章 Webots官方Tutorial 1
目录
- 第二章 Webots官方Tutorial 1
- 前言
- 一、Tutorial 1: Your First Simulation in Webots
- 二、创建一个新世界
- 三、添加一个e-puck机器人
- 四、创建一个新的控制器
- 总结
前言
开始学会使用Webots吧!(注意每步都要保存,防止新建的物体消失)
一、Tutorial 1: Your First Simulation in Webots
目标是熟悉 Webots的用户界面和基本概念。
需要我们创建一个简单的环境:一个地板和墙组成的区域、几个箱子、一个机器人和使其移动的控制器程序。
二、创建一个新世界
2.1 Hands-on #2
File / New / New Project Directory
会生成.wbt
文件
- WorldInfo: 包含一些世界参数.
- Viewpoint: 视角参数.
- TexturedBackground: 背景
- TexturedBackgroundLight: 与背景相关的灯光
- RectangleArena: 当前所示的矩形地板floor
2.2 Hands-on #3
地板及墙的尺寸设置。
2.3 Hands-on #4
添加木箱,设置尺寸size、坐标translation,复制粘贴Ctrl+c\v。
点击+,选择PROTO nodes(Webots Projects)/objects/factory/containers/ WoodenBox (Solid)
三、添加一个e-puck机器人
3.1 Hands-on #5
点击+,选择PROTO nodes(Webots Projects)/robots/gctronic/e-puck/E-puck(Robot)
运行环境,机器人动起来。
3.2 Hands-on #6
alt+鼠标左键 可拖拽机器人。
同理,给箱子设置质量mass后,可以进行拖拽。
3.3 Hands-on #7
设置仿真基准时间步长basicTimeStep
四、创建一个新的控制器
本文采用Python
语言
4.1 Hands-on #8
File / New / New Robot Controller
4.2 Hands-on #9
机器人向前运动控制代码:
from controller import Robot, Motor
TIME_STEP = 64
# create the Robot instance.
robot = Robot()
# get the motor devices
leftMotor = robot.getDevice('left wheel motor')
rightMotor = robot.getDevice('right wheel motor')
# set the target position of the motors
leftMotor.setPosition(10.0)
rightMotor.setPosition(10.0)
while robot.step(TIME_STEP) != -1:
pass
4.3 Hands-on #10
运动速度控制代码:
from controller import Robot, Motor
TIME_STEP = 64
MAX_SPEED = 6.28
# create the Robot instance.
robot = Robot()
# get a handler to the motors and set target position to infinity (speed control)
leftMotor = robot.getDevice('left wheel motor')
rightMotor = robot.getDevice('right wheel motor')
leftMotor.setPosition(float('inf'))
rightMotor.setPosition(float('inf'))
# set up the motor speeds at 10% of the MAX_SPEED.
leftMotor.setVelocity(0.1 * MAX_SPEED)
rightMotor.setVelocity(0.1 * MAX_SPEED)
while robot.step(TIME_STEP) != -1:
pass
总结
恭喜你完成了教程1,在此你应该初步了解了Webots的基本概念、布局和简单设计。
标签:rightMotor,robot,Robot,motor,Hands,Webots,tutorial From: https://www.cnblogs.com/YIKeLB/p/17085185.html