首页 > 其他分享 >Webots tutorial 7

Webots tutorial 7

时间:2023-02-03 14:14:44浏览次数:67  
标签:WHEEL USE name 0.05 Webots rotation translation tutorial

第八章 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

相关文章

  • Webots tutorial 8
    第九章Webots官方Tutorial8目录第九章Webots官方Tutorial8Tutorial8:theSupervisor二、设置环境并添加Supervisor三、使用Supervisor移动对象四、生成和删除结点......
  • Webots tutorial 5
    第六章Webots官方Tutorial5目录第六章Webots官方Tutorial5一、Tutorial5:CompoundSolidandPhysicsAttributes二、组合实体三、物理属性3.1Handson#33.2Han......
  • Webots tutorial 4
    第五章Webots官方Tutorial4目录第五章Webots官方Tutorial4一、Tutorial4:MoreaboutControllers二、新建一个控制器2.1Handson#1三、e-puck模型四、设计控制......
  • 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......