用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill webots命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | webots |
| description | Webots 机器人仿真开发技能 - 机器人建模、控制器开发、传感器配置、ROS/ROS2 集成 |
| argument-hint | webots仿真 OR webots机器人 OR 创建控制器 OR 传感器配置 |
| user-invocable | true |
用于 Webots 机器人仿真环境的配置和开发
当需要以下帮助时使用此技能:
# 下载 Webots
# https://cyberbotics.com/#download
# Ubuntu 安装
sudo apt install ./webots_*.deb
# 或使用 AppImage
chmod +x webots.AppImage
./webots.AppImage
# 从命令行启动
webots
# 打开特定世界文件
webots /path/to/world.wbt
my_project/
├── worlds/
│ └── my_robot.wbt # 世界文件
├── protos/
│ └── MyRobot.proto # 自定义 PROTO 定义
├── controllers/
│ ├── my_controller/ # 控制器目录
│ │ ├── my_controller.c # C 控制器
│ │ ├── Makefile
│ │ └── (其他文件)
│ └── python_controller/ # Python 控制器
│ └── robot.py
└── libraries/
└── (外部库)
PROTO MyRobot [
field SFVec3f translation 0 0 0
field SFRotation rotation 0 1 0 0
field SFString name "my_robot"
field SFFloat wheelRadius 0.1
]
{
Robot {
translation IS translation
rotation IS rotation
name IS name
children [
# 主体
Shape {
appearance Appearance {
material Material {
diffuseColor 0.3 0.3 0.3
}
}
geometry Box {
size 0.5 0.3 0.1
}
}
# 轮子
HingeJoint {
jointParameters HingeJointParameters {
anchor 0.2 0.15 0
}
device Slot {
device Slot {
wheel Motor {
maxVelocity 10
}
}
}
endPoint Solid {
children [
Shape {
appearance Appearance {
material Material { diffuseColor 0.1 0.1 0.1 }
}
geometry Cylinder {
height 0.05
radius 0.1
}
}
]
boundingObject Box {
size 0.1 0.1 0.05
}
}
}
]
controller "my_controller"
boundingObject Box {
size 0.5 0.3 0.1
}
}
}
PROTO DiffDriveRobot [
field SFVec3f translation 0 0 0.1
field SFRotation rotation 0 1 0 0
field SFString name "diff_drive"
field SFFloat wheelRadius 0.1
field SFFloat axleLength 0.3
]
{
Robot {
translation IS translation
rotation IS rotation
name IS name
children [
# 主体
Solid {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.4 0.4 0.8
}
}
geometry Box {
size 0.4 0.3 0.1
}
}
]
}
# 左轮
HingeJoint {
jointParameters HingeJointParameters {
anchor 0 0.15 0
axis 1 0 0
}
device Slot {
device Slot {
wheel Motor {
maxVelocity 10
maxTorque 10
}
}
}
endPoint Solid {
children [
Shape {
appearance Appearance {
material Material { diffuseColor 0.2 0.2 0.2 }
}
geometry Cylinder {
height 0.05
radius IS wheelRadius
}
}
]
boundingObject Cylinder {
height 0.05
radius IS wheelRadius
}
}
}
# 右轮
HingeJoint {
jointParameters HingeJointParameters {
anchor 0 -0.15 0
axis 1 0 0
}
device Slot {
device Slot {
wheel Motor {
maxVelocity 10
maxTorque 10
}
}
}
endPoint Solid {
children [
Shape {
appearance Appearance {
material Material { diffuseColor 0.2 0.2 0.2 }
}
geometry Cylinder {
height 0.05
radius IS wheelRadius
}
}
]
boundingObject Cylinder {
height 0.05
radius IS wheelRadius
}
}
}
# 激光雷达
Lidar {
name "lidar"
translation 0.2 0 0.05
numberOfLayers 1
fieldOfView 3.14
maxRange 10
resolution 0.01
}
# 摄像头
Camera {
name "camera"
translation 0.15 0 0.05
width 640
height 480
fieldOfView 1.0
}
]
controller "my_controller"
boundingObject Box {
size 0.5 0.4 0.15
}
}
}
# controllers/my_robot/robot.py
from controller import Robot, Camera, Lidar
class MyRobot:
def __init__(self):
self.robot = Robot()
self.time_step = int(self.robot.getBasicTimeStep())
# 获取执行器
self.left_motor = self.robot.getMotor('left_wheel')
self.right_motor = self.robot.getMotor('right_wheel')
# 获取传感器
self.camera = self.robot.getCamera('camera')
self.lidar = self.robot.getLidar('lidar')
self.gps = self.robot.getGPS('gps')
self.gyro = self.robot.getGyro('gyro')
# 启用传感器
self.camera.enable(self.time_step)
self.lidar.enable(self.time_step)
self.gps.enable(self.time_step)
self.gyro.enable(self.time_step)
def run(self):
.robot.step(.time_step) != -:
image = .camera.getImage()
range_data = .lidar.getRangeImage()
position = .getPosition()
.set_velocity(, )
():
.left_motor.setVelocity(left_vel)
.right_motor.setVelocity(right_vel)
():
gps_values = .gps.getValues()
gps_values
robot = MyRobot()
robot.run()
// controllers/my_robot/my_robot.c
#include <webots/robot.h>
#include <webots/motor.h>
#include <webots/distance_sensor.h>
#include <webots/camera.h>
#define TIME_STEP 10
int main(int argc, char **argv) {
wb_robot_init();
// 获取设备
WbDeviceTag left_motor = wb_robot_get_device("left_wheel");
WbDeviceTag right_motor = wb_robot_get_device("right_wheel");
WbDeviceTag camera = wb_robot_get_device("camera");
// 设置电机模式
wb_motor_set_position(left_motor, INFINITY);
wb_motor_set_position(right_motor, INFINITY);
// 启用摄像头
wb_camera_enable(camera, TIME_STEP);
while (wb_robot_step(TIME_STEP) != -1) {
// 获取摄像头数据
const unsigned char *image = wb_camera_get_image(camera);
// 设置速度
wb_motor_set_velocity(left_motor, 2.0);
wb_motor_set_velocity(right_motor, 2.0);
}
wb_robot_cleanup();
return 0;
}
gps = self.robot.getGPS('gps')
gps.enable(self.time_step)
position = gps.getValues() # [x, y, z]
gyro = self.robot.getGyro('gyro')
accelerometer = self.robot.getAccelerometer('accelerometer')
gyro.enable(self.time_step)
accelerometer.enable(self.time_step)
angular_velocity = gyro.getValues() # [wx, wy, wz]
linear_acceleration = accelerometer.getValues() # [ax, ay, az]
# 红外传感器
ds = self.robot.getDistanceSensor('ds_left')
ds.enable(self.time_step)
distance = ds.getValue() # 0-4095 (距离越近值越大)
# 轮子编码器
left_encoder = self.robot.getEncoder('left_wheel')
right_encoder = self.robot.getEncoder('right_wheel')
left_encoder.enable(self.time_step)
right_encoder.enable(self.time_step)
left_angle = left_encoder.getValue() # 弧度
# 安装 ROS2 包
sudo apt install ros-humble-webots-ros2
# 或从源码
cd ~/ros2_ws/src
git clone https://github.com/cyberbotics/webots_ros2.git
cd webots_ros2
rosdep install -r --from-paths . --ignore-src -y
colcon build
# launch/webots.launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
def generate_launch_description():
return LaunchDescription([
IncludeLaunchDescription(
PythonLaunchDescriptionSource(
'/opt/webots/projects/default/worlds/ros2.launch.py'
)
),
Node(
package='webots_ros2_driver',
executable='webots_ros2_driver',
output='screen',
parameters=[{
'robot_description': 'robot_description',
'robot_name': 'my_robot',
}]
)
])
# ros2_driver/my_driver.py
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Twist
from sensor_msgs.msg import Image
class WebotsDriver(Node):
def __init__(self):
super().__init__('webots_driver')
# 订阅 cmd_vel
self.cmd_vel_sub = self.create_subscription(
Twist,
'/cmd_vel',
self.cmd_vel_callback,
10)
# 发布图像
self.image_pub = self.create_publisher(Image, '/camera', 10)
def cmd_vel_callback(self, msg):
# 转换为 Webots motor 控制
velocity = (msg.linear.x + msg.angular.z * 0.15) / 0.1
# 设置电机速度
#WorldInfo {
# basicTimeStep 10
# FPS 30
# coordinateSystem "NUE"
#}
Viewpoint {
orientation -0.3 0.9 0.3 2.5
position -3 -3 2
}
Background {
skyColor 0.5 0.7 1.0
}
Floor {
size 10 10
tileSize 1 1
appearance PBRAppearance {
baseColor 0.5 0.5 0.5
roughness 1
}
}
DEF MY_ROBOT DiffDriveRobot {
translation 0 0 0.1
}
解决方案:
解决方案:
解决方案: