Introduction to ROS (4)-basic use of Gazebo

Introduction to ROS (4)
  -Gazebo's basic use of iwehdio's blog garden: https://www.cnblogs.com/iwehdio/

Reference tutorial:
gazebo introductory tutorial (1) Installation, UI introduction: https://blog.csdn.net/weixin_41045354/article/details/84881498
gazebo introductory tutorial (2) Building a simple model: https://blog.csdn.net / weixin_41045354 / article / details / 103668162

1. Interface overview

  • Uninstall Gazebo9 installed in ros-melodic version and install Gazebo11.

    $ sudo apt-get remove gazebo9 gazebo9-common gazebo9-plugin-base libgazebo9:amd64 libgazebo9-dev:amd64 ros-melodic-gazebo-*                   
    
    $ sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
    $ wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
    $ sudo apt-get update
    $ sudo apt-get install gazebo11
    $ sudo apt-get install libgazebo11-dev
    
  • start up:

    • Command roslaunch gazebo_ros empty_world.launchline: .
    • Global command: Alt + F2, type gazebo and press Enter.
  • Software view:

    • Scenario: Show the simulation model.
    • Left panel:
      • WORLD: The "World" tab displays the models currently in the scene and allows you to view and modify model parameters such as their poses. You can also change the camera angle by expanding the "GUI" option and adjusting the camera pose.
      • INSERT: "Insert" tab to add new objects (models) to the simulation. To view the list of models, you may need to click the arrow to expand the folder. Click (and release) on the model you want to insert, then click again in the scene to add it.
      • LAYER: The "Layer" tab organizes and displays the different visualization groups available in the simulation (if any). A layer can contain one or more models. Turning the layer on or off will show or hide the model in that layer. This is an optional feature, so in most cases this tab will be empty.
    • Right panel: The Gazeb interface hides the right panel by default. Click and drag the bar to open it. The right panel can be used to interact with the moving parts of the selected model (joint). If no model is selected in the scene, the panel will not display any information.
    • Upper toolbar: It is Gazebo ’s main toolbar, which contains some of the most commonly used options for interacting with the simulator, such as: select, move, rotate, and zoom objects; create simple shapes (such as cubes, spheres, cylinders ); Copy / paste model options.
      • Select mode: navigate through the scene.
      • Translate mode: Select the model to be moved.
      • Rotate mode: Select the model to be rotated.
      • Scale mode: Select the model to be scaled.
      • Undo / redo: undo / redo the operation in the scene.
      • Simple shape: Insert a simple shape into the scene.
      • Lights: Add lights to the scene.
      • Copy / paste: copy / paste the model in the scene.
      • Align: Align the models with each other.
      • Snap: Align one model with another model.
      • Change view: View the scene from all angles.
    • Bottom toolbar: displays data about the simulation, such as simulation time and its relationship with actual time.
      • "Simulation time" refers to the speed of time elapsed in the simulator while the simulation is running. The simulation time can be slower or faster than real time, depending on the amount of calculation required to run the simulation.
      • "Real time" refers to the actual time elapsed in real life while the simulator is running. The relationship between simulation time and real-time is called "real-time factor" (RTF). It is the ratio of simulation time to real time. RTF measures the speed or rate at which simulation runs are compared to real-time.
      • Gazebo ’s state of the world is calculated every iteration. You can see the number of iterations on the right side of the bottom toolbar. Each iteration advances the simulation by a fixed number of seconds, called the step size. By default, the step size is 1 ms. You can press the pause button to pause the simulation and use the step buttons to step through several steps.
    • Menu bar: More specific functions.
    • Mouse operation:
      • shift + left button: rotate the viewing angle.
      • Left button: Pan time.
      • Wheel: Zoom size.

2. Create a simple robot

  • Enter the model editor, click Edit in the top menu bar, and then select Model Editor. Alternatively, use the hotkey Ctrl + M.

    • The left panel and top toolbar only contain widgets for editing and creating model parts.
    • The upper toolbar contains tools for editing the model. Includes tools for interacting with objects in the scene. Available tools include selection, pan, zoom, rotate, undo and redo, copy and paste, alignment, snapping, view adjustment, and joint creation.
    • The left panel has two labels for editing models.
      • Insert Insert label: tool for adding joints and model constraints.
        • You can add new parts (links and models) to the model editor. There are three parts.
        • Simple shapes: These are the basic geometric shapes that can be inserted to form links in the model.
        • Custom shape: This Add button allows you to import a custom grid from a model link. Currently, it supports COLLADA (.dae), 3D Systems (.stl), Wavefront (.obj) and W3C SVG (.svg) files.
        • Model database: has a list of models. They can be inserted into the Model Editor in the same way as simple shapes. After insertion, they are called nested models
      • Model "Model" tab: allows editing of model properties and content.
        • You can set the name and basic parameters of the model to be built. It shows a list of links, joints, model constraints and plug-ins in the model. You can use Link Inspector to modify the parameters.
        • You can use the following methods to open it. Double-click the item in the list /
          double-click the item in the scene / right-click the item in the list, then select Open Link Inspector / right-click the item in the scene, and then select Open Link Inspector.
  • Create a vehicle:

    1. Chassis.

      • In the "insert" tab of the left panel, click once on the "box" icon, move the cursor to any location in the "scene", and click again to release the box.

      • Next, adjust the size of the box. We can do this by selecting the "Zoom" (fourth) tool on the top toolbar. Select the box in "Scene" and the RGB mark should be displayed above the box. The red mark represents the X axis, the green represents Y, and the blue represents Z.

      • Lower the chassis closer to the ground. Double-click the chassis model to bring up the link inspector. Scroll down to the bottom of the link tab to find the Pose parameter and change it to 0.4m, then click outside the box. Click OK to save the changes and close the inspector.

      • There are two Pose in the link tab. It is important to note that the Pose below is set.

    2. Front wheel.

      • Insert the cylinder from the insert tab on the left panel.

      • Use Link Inspector to rotate it along the X axis. Double-click the cylinder, scroll to the Pose section at the bottom, and change the Roll to 1.5707 radians (90 degrees), then click outside the box. Do not turn off the inspector for now.

      • Next, adjust the wheel size by providing the exact size. Go to the visual tab to view the visual list in this link. Scroll down to the Geometry section and change it to Radius 0.3m and Length 0.25m.

      • Now, smaller cylinders can be seen inside the larger cylinder. Because we only changed the visual geometry, not the collision. Visual is a graphical representation of the link and does not affect the physical simulation. Switch to the collision option. Set Radius: 0.3m and Length: 0.25m Click OK to save changes and close the inspector.

      • Create another front wheel by copying and pasting. Select the front wheel you just created, click Copy (the sixth from the right) in the upper toolbar, then click Paste (the fifth from the right), and click Insert Copy in the scene.

      • Now, by aligning the chassis in the positive direction of the X axis (red mark in the scene), make sure that the vehicle can drive correctly. When adding wheels in the next step, make sure they are at the end of the vehicle that extends in the positive direction of the X axis.

      • The chassis and wheels are currently freely moving bodies. To limit their movement, we will add joints between each wheel and the chassis. Click the Joint icon on the top toolbar (the first from the right) to bring up the Create Joint dialog box.

      • The Create Joint dialog box contains joint properties that are usually specified for joints. Before configuring any attributes, you will be prompted to select the parent and child links of the joint. Move your mouse over the chassis in the Scene to highlight it, and click to set it as the parent of the joint.

        • Move the mouse to the left front wheel; a line should now extend from the origin of the chassis to the end of the mouse. Click the wheel to set it as a child of the joint. Create a new joint. By default, it is Revolute, which happens to be the Joint Types we want.
      • Next, we need to configure the rotation axis of the wheel. In the Create Joint dialog, find the Joint axis and change it to Z (0, 0, 1). Note the color display on each axle of the wheel. You should see a yellow ring now appear above the blue arrow of the joint diagram, indicating that it is the axis of rotation.

      • To align the wheels with the chassis, we will use different alignment options Align links in the "Joint Creation" dialog. First, we will align on the X axis, so click the X Align Max option to view the alignment results. The cylinder should be highlighted to indicate that its posture has changed.

      • In our example, we want the wheels to be flush with the chassis. To bring the wheels closer, click the Y Align Max option. However, this is not what we want. Click the Reverse option next to the Y alignment option to align the minimum value of the wheel (in the opposite direction of the maximum value) with the maximum value of the chassis. Finally, click Create.

        • Note that this Reverse option applies to child links because the default alignment shown in the drop-down list below is configured as Child to Parent. If the Parent to Child configuration is set, the Reverse option will be applied to the parent link
      • To place the wheel above the ground, double-click the wheel to open the link inspector. We can use the bottom part of the Pose dialog box to move the wheels. Assuming the radius of the wheel is 0.3m, go ahead and change the Z position to 0.3m to place on the ground, then press OK.

      • Do the same for the other front wheel. Note the Y Align Min option to align the right wheel with the other side of the chassis.

    3. Casters.

      • Click the "spherical" button on the left panel and insert it into the scene.
      • Adjust the size of the sphere by providing the same exact dimensions as the front wheels. Visual tab Geometry section and change its Radius to 0.2m. Make sure to do the same with the collision size in the "collision" tab.
      • To create a joint between the caster and the chassis, click the Joint icon on the top toolbar to display the Joint Creation dialog box. Move the mouse to the scene, then select the chassis as the parent link and the ball as the child link.
      • The casters roll in all directions and there is no specific axis of rotation. In the gazebo, this is simulated using ball joints. Therefore, in the Joint types option, select Ball (ball connection).
      • Next, align the casters so that they are centered with the chassis and at the rear. In the Align links section, select Y Align Center, select the option to center on the Y axis, and then select X Align Min (minimum alignment) to move the caster to the rear right of the wheel. Press the Create button to complete the joint creation process.
      • Open the link inspector and set the Z position to 0.2m.
    4. Add sensors.

      • Select the Insert tab to view the list of models (Model Database) available in this section. Find "Depth Camera" in the list and click it to start downloading the model.

      • It looks like a small cube. Move your mouse over the scene and click on the empty space in front of the car to insert the depth camera. Move the depth camera so that it is located on the top of the chassis at the front of the vehicle and roughly at the center of the Y axis.

      • Fix the depth camera to the case. Click the "joint" icon in the top toolbar to open the "Joint Creation" dialog box. Move the mouse to the scene, and then select the chassis as the parent link and the depth camera as the child link. Select the Fixed option (ie fixed connection).

    5. Add a plugin.

      • Under the Model Plugins option, click the Add button, and a "Model Plugin Checker" pops up.

      • The plugin is named smallcar_follower, and the plugin used is libFollowerPlugin.so.

    6. Save the model and exit the model editor.

      • To test whether the plug-in is working properly, insert a box in front of the car and observe the car moving slowly towards it.


iwehdio's blog garden: https://www.cnblogs.com/iwehdio/

Guess you like

Origin www.cnblogs.com/iwehdio/p/12751106.html