第八章 Webots官方Tutorial 7
目录
一、Tutorial 7: Your First PROTO
本教程的目的是创建与教程6中的四轮机器人相对应的 PROTO文件。方便直接添加4轮机器人。
参考链接:https://cyberbotics.com/doc/guide/tutorial-7-your-first-proto?tab-os=windows&tab-language=python
二、复制Robot的定义
1)在工程文件下的protos文件夹内创建一个文本文档文件,文件命名为FourWheelsRobot.proto,起始内容添加为:
PROTO FourWheelsRobot [
field SFVec3f translation 0 0 0.04
field SFRotation rotation 1 0 0 1.5708
field SFFloat bodyMass 1
field SFString controller "wheel_controller"
]
{
Robot {
}
}
2)在worlds文件夹内找到世界文件(例:my_first_simulation.wbt
),右键记事本打开,找到Robot结点
的内容:
Robot {
translation -0.15000000000000002 -1.1019579575868324e-07 0.03986048964938831
rotation 1 6.07375099382219e-16 6.860377807049861e-16 1.5707963267948974
children [
DEF BODY Shape {
appearance PBRAppearance {
baseColor 1 0 0
}
geometry Box {
size 0.1 0.05 0.2
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -8.046450960340255e-16
anchor 0.06 0 0.05
}
device [
RotationalMotor {
name "wheel1"
}
]
endPoint DEF WHEEL1 Solid {
translation 0.06 0 0.05
rotation -8.046421404129807e-16 -1 8.046450960340255e-16 1.5708
children [
DEF WHEEL Shape {
appearance PBRAppearance {
baseColor 0 1 0
}
geometry Cylinder {
height 0.02
radius 0.04
}
}
]
name "wheel1"
boundingObject USE WHEEL
physics DEF WHEEL_PH Physics {
}
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -1.7763568394002505e-15
anchor -0.06 0 0.05
}
device [
RotationalMotor {
name "wheel2"
}
]
endPoint Solid {
translation -0.06 0 0.05
rotation -1.7763503144892267e-15 -1 1.7763568394002505e-15 1.5707999999999998
children [
USE WHEEL
]
name "wheel2"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -1.7763568394002505e-15
anchor 0.06 0 -0.05
}
device [
RotationalMotor {
name "wheel3"
}
]
endPoint Solid {
translation 0.06 0 -0.05
rotation -1.776358650601804e-15 -0.9999999999999999 1.7763568394002503e-15 1.5707953071795862
children [
USE WHEEL
]
name "wheel3"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -8.881784197001252e-16
anchor -0.06 0 -0.05
}
device [
RotationalMotor {
name "wheel4"
}
]
endPoint Solid {
translation -0.06 0 -0.05
rotation -8.88179325300902e-16 -0.9999999999999999 8.881784197001251e-16 1.5707953071795862
children [
USE WHEEL
]
name "wheel4"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
DistanceSensor {
translation 0.025 0 0.1
rotation 0 -1 0 1.27
children [
Shape {
appearance PBRAppearance {
baseColor 0 0 1
}
geometry Box {
size 0.01 0.01 0.01
}
}
]
name "ds_left"
}
DistanceSensor {
translation -0.025 0 0.1
rotation 0 -1 0 1.87
children [
Shape {
appearance PBRAppearance {
baseColor 0 0 1
}
geometry Box {
size 0.01 0.01 0.01
}
}
]
name "ds_right"
}
]
boundingObject USE BODY
physics Physics {
density -1
mass 1
}
controller "wheel_controller"
}
将此部分替换FourWheelsRobot.proto文件里相应的Robot{}部分,并修改translation、rotation、mass和controller(此处可不做修改,如需要可在软件里做修改)。
PROTO FourWheelsRobot [
field SFVec3f translation 0 0 0.04
field SFRotation rotation 1 0 0 1.5708
field SFFloat bodyMass 1
field SFString controller "wheel_controller"
]
{
Robot {
translation IS translation
rotation IS rotation
children [
DEF BODY Shape {
appearance PBRAppearance {
baseColor 1 0 0
}
geometry Box {
size 0.1 0.05 0.2
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -8.046450960340255e-16
anchor 0.06 0 0.05
}
device [
RotationalMotor {
name "wheel1"
}
]
endPoint DEF WHEEL1 Solid {
translation 0.06 0 0.05
rotation -8.046421404129807e-16 -1 8.046450960340255e-16 1.5708
children [
DEF WHEEL Shape {
appearance PBRAppearance {
baseColor 0 1 0
}
geometry Cylinder {
height 0.02
radius 0.04
}
}
]
name "wheel1"
boundingObject USE WHEEL
physics DEF WHEEL_PH Physics {
}
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -1.7763568394002505e-15
anchor -0.06 0 0.05
}
device [
RotationalMotor {
name "wheel2"
}
]
endPoint Solid {
translation -0.06 0 0.05
rotation -1.7763503144892267e-15 -1 1.7763568394002505e-15 1.5707999999999998
children [
USE WHEEL
]
name "wheel2"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -1.7763568394002505e-15
anchor 0.06 0 -0.05
}
device [
RotationalMotor {
name "wheel3"
}
]
endPoint Solid {
translation 0.06 0 -0.05
rotation -1.776358650601804e-15 -0.9999999999999999 1.7763568394002503e-15 1.5707953071795862
children [
USE WHEEL
]
name "wheel3"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
HingeJoint {
jointParameters HingeJointParameters {
position -8.881784197001252e-16
anchor -0.06 0 -0.05
}
device [
RotationalMotor {
name "wheel4"
}
]
endPoint Solid {
translation -0.06 0 -0.05
rotation -8.88179325300902e-16 -0.9999999999999999 8.881784197001251e-16 1.5707953071795862
children [
USE WHEEL
]
name "wheel4"
boundingObject USE WHEEL
physics USE WHEEL_PH
}
}
DistanceSensor {
translation 0.025 0 0.1
rotation 0 -1 0 1.27
children [
Shape {
appearance PBRAppearance {
baseColor 0 0 1
}
geometry Box {
size 0.01 0.01 0.01
}
}
]
name "ds_left"
}
DistanceSensor {
translation -0.025 0 0.1
rotation 0 -1 0 1.87
children [
Shape {
appearance PBRAppearance {
baseColor 0 0 1
}
geometry Box {
size 0.01 0.01 0.01
}
}
]
name "ds_right"
}
]
boundingObject USE BODY
physics Physics {
density -1
mass IS bodyMass
}
controller IS controller
}
}
三、使用PROTO结点
添加结点:PROTO nodes (Current Project) / FourWheelsRobot (Robot)
- 即将机器人的PROTO结点添加到了环境里,因name相同需修改原来的Robot结点的名字name,以便运行仿真。
- 更多信息关于PROTO,以便定义全局变量,方便在软件里做相应修改。
总结
现在,学习了如何复制PROTO文件中的节点定义,以及如何打开PROTO字段并将其链接到内部节点字段。方便直接添加PROTO结点仿真 而不是自己逐步再创建对象实体。
标签:WHEEL,USE,name,0.05,Webots,rotation,translation,tutorial From: https://www.cnblogs.com/YIKeLB/p/17085231.html