Robot Controllers

Webots 机器人控制器技能 - Python/C++ 控制器、电机控制、传感器读取

miuav d8899ca 1.2 KB Updated

File contents

Webots Robot Controllers Skill

用于开发 Webots 机器人控制器


何时使用

当需要以下帮助时使用此技能:

  • 编写机器人控制器
  • 控制电机运动
  • 读取传感器数据

快速参考

Python 控制器

from controller import Robot, Motor, Lidar

robot = Robot()
timestep = int(robot.getBasicTimeStep())

# 获取设备
motor = robot.getMotor('left wheel')
lidar = robot.getLidar('lidar')

# 主循环
while robot.step(timestep) != -1:
    motor.setVelocity(1.0)

控制器类型

差速驱动

class DiffDriveController:
    def __init__(self, robot):
        self.left_motor = robot.getMotor('left wheel')
        self.right_motor = robot.getMotor('right wheel')
        
    def move(self, linear, angular):
        v_left = linear - angular * self.wheel_separation / 2
        v_right = linear + angular * self.wheel_separation / 2
        self.left_motor.setVelocity(v_left)
        self.right_motor.setVelocity(v_right)

另见

miuav/vibe-coding-ros2/tree/main/agents/skills/simulator/webots/robot-controllers commit d8899ca599

Frequently asked questions

npx skillmds@latest add miuav/robot-controllers