首页 > 其他分享 >Webots tutorial 4

Webots tutorial 4

时间:2023-02-03 13:44:20浏览次数:63  
标签:控制器 80.0 MAX 0.5 psValues Webots SPEED tutorial

第五章 Webots官方Tutorial 4


目录


一、Tutorial 4: More about Controllers

本教程介绍Webot中机器人控制器编程的基础知识。即了解节点和控制器API之间的联系,机器人控制器初始化和重置,如何初始化机器人设备,如何获取传感器值,如何命令致动器,以及如何编写简单的反馈控制。

参考链接:https://cyberbotics.com/doc/guide/tutorial-4-more-about-controllers?tab-os=windows&tab-language=python

二、新建一个控制器

2.1 Hands on #1

(此处为python语言,命名为EPuckAvoidCollision)

三、e-puck 模型

8个距离传感器(ps0~ps7)

四、设计控制器

EPuckAvoidCollision.py
此处易从函数名理解它的作用。

from controller import Robot, DistanceSensor, Motor

# time in [ms] of a simulation step
TIME_STEP = 64

MAX_SPEED = 6.28

# create the Robot instance.
robot = Robot()

# initialize devices
ps = []
psNames = [
    'ps0', 'ps1', 'ps2', 'ps3',
    'ps4', 'ps5', 'ps6', 'ps7'
]

for i in range(8):
    ps.append(robot.getDevice(psNames[i]))
    ps[i].enable(TIME_STEP)

leftMotor = robot.getDevice('left wheel motor')
rightMotor = robot.getDevice('right wheel motor')
leftMotor.setPosition(float('inf'))
rightMotor.setPosition(float('inf'))
leftMotor.setVelocity(0.0)
rightMotor.setVelocity(0.0)

# feedback loop: step simulation until receiving an exit event
while robot.step(TIME_STEP) != -1:
    # read sensors outputs
    psValues = []
    for i in range(8):
        psValues.append(ps[i].getValue())

    # detect obstacles
    right_obstacle = psValues[0] > 80.0 or psValues[1] > 80.0 or psValues[2] > 80.0
    left_obstacle = psValues[5] > 80.0 or psValues[6] > 80.0 or psValues[7] > 80.0

    # initialize motor speeds at 50% of MAX_SPEED.
    leftSpeed  = 0.5 * MAX_SPEED
    rightSpeed = 0.5 * MAX_SPEED
    # modify speeds according to obstacles
    if left_obstacle:
        # turn right
        leftSpeed  = 0.5 * MAX_SPEED
        rightSpeed = -0.5 * MAX_SPEED
    elif right_obstacle:
        # turn left
        leftSpeed  = -0.5 * MAX_SPEED
        rightSpeed = 0.5 * MAX_SPEED
    # write actuators inputs
    leftMotor.setVelocity(leftSpeed)
    rightMotor.setVelocity(rightSpeed)

总结

到此,你应该学会了简单的机器人控制器设计。

附加:
1.每个控制器程序作为Webots进程的子进程执行。控制器进程不与Webot共享任何内存(相机图像除外),它可以在Webot以外的其他CPU(或CPU内核)上运行。
2. 控制器代码与“libController”动态库链接。此库处理控制器和Webot之间的通信。

标签:控制器,80.0,MAX,0.5,psValues,Webots,SPEED,tutorial
From: https://www.cnblogs.com/YIKeLB/p/17085210.html

相关文章

  • Webots tutorial 2
    第三章Webots官方Tutorial2目录第三章Webots官方Tutorial2一、Tutorial2:ModificationoftheEnvironment二、一个新仿真2.1Hands-on#1三、修改地板Floor3.1Ha......
  • Webots tutorial 3
    第四章Webots官方Tutorial3目录第四章Webots官方Tutorial3一、Tutorial3:Appearance二、灯光三、修改墙的外观3.1Hands-on#2四、给球添加一个现有外观4.1Hands-......
  • Webots tutorial 1
    第二章Webots官方Tutorial1目录第二章Webots官方Tutorial1前言一、Tutorial1:YourFirstSimulationinWebots二、创建一个新世界2.1Hands-on#22.2Hands-on#3......
  • Webots下载安装 + Pycharm联调
    第一章Webots安装目录第一章Webots安装前言一、Webots是什么?二、WebotsR2022b安装1.下载2.安装3.Pycharm作为IDE3.1设置环境变量3.2Webots设置总结前言本系列......
  • Firefly Amazon UK PC control installation tutorial
    FireflyAmazonUKPCcontrolinstallationtutorial1.TurnoffthePCfirewallandanti-virussoftware,itisbesttouninstalltheanti-virussoftware2.Downl......
  • Firefly Amazon PC control installation tutorial
    FireflyAmazonPCcontrolinstallationtutorial1.TurnoffthePCfirewallandanti-virussoftware,itisbesttouninstalltheanti-virussoftware2.Download......
  • Firefly Amazon US PC control installation tutorial
    FireflyAmazonUSPCcontrolinstallationtutorial1.TurnoffthePCfirewallandanti-virussoftware,itisbesttouninstalltheanti-virussoftware2.Downl......
  • Quartz.Net 官方教程 Tutorial 3/3
    Schedule相关属性设置扩展属性方式varhost=Host.CreateDefaultBuilder().ConfigureServices(services=>{services.AddQuartz(opt=>......
  • Abstraction, intuition, and the “monad tutorial fallacy”
    WhileworkingonanarticlefortheMonad.Reader,I’vehadtheopportunitytothinkabouthowpeoplelearnandgainintuitionforabstraction,andtheimplica......
  • cURL Tutorial
    created:2023/1/23 cURLbasicusage curl<url>          DownloadingFileswithcURL       ......