Webots + ROS learning record (3) - four mobile robots

Webots + ROS learning record (3) - four mobile robots

First, four mobile robot model

The purpose of this tutorial is to create from scratch your first robot. This robot will be a body, two wheels and four distance sensors. The results shown in Fig. FIG 2 shows a plan view of the robot coordinate relationship.
figure 1Figure II - the representative body of the robot coordinate system and the wheels are in the same direction.  Their vector + x (red) are defined on the left side of the robot, their vector + y (green) defines the top of the robot, their vector + z (blue) defines a front portion of the robot.  However, different from a direction sensor, which sensor indicates the + x direction vector

Second, step

a) Create a new simulation

  1. Create a new project, make sure your new world there are floors, walls and lighting (ground, the walls and the lighting) save the world file 4_wheels_robot.wbt.

  2. Before giving the robot model to create a rule, we need some definitions.

  • Solid collection that contains the node and all of its descendent nodes is called a solid node. Similar definitions apply to the Device, Robot, Joint and Motor node. The main structure of the robot model is a physical node in the tree are connected together. Joint for adding a node (or more) degrees of freedom (DOF) between a parent node and child node. Direct parent node and child nodes Joint nodes are real. Derived from the Joint node allows you to create different types of constraints between the solid node links.
  • In our example: There are four degrees of freedom of the robot corresponding to the wheel motors. It can be divided into five entities nodes: the body and four wheels.

b) the robot into the entity node

  1. In the final scene tree to add a node Robot HingeJoints having four nodes, the node has a child node Solid
    image 3

  2. Add shape node contains Box geometry of the robot node. The shape of the color to red. The shape may also be defined using fields boundingObject robot node. Box dimensions are (0.1,0.05,0.2). Adding a node Physics robot. Figure 4 shows all of the nodes defined in the robot. So far, only achieved direct children of the root node of the robot.Figure 4

c) create HingeJoints

  1. Add a HingeJointParameters node. The initial position of the wheel is determined by the entity node translation and rotation. And HingeJointParameters child nodes define the rotation origin (Anchor) and the rotation axis (axis) of the hinge by an optional node. For the first wheel, it shall be defined as the translation entity (0.06,0,0.05), relative to a gap between the vehicle body and the wheel. HingeJointParameters-anchor should be defined as (0.06,0,0.05) to define the origin of rotation (with respect to the body). Finally, HingeJointParameters-
    Axis in our case it along the x-axis, so the set (1,0,0).

  2. To complete the missing nodes, to obtain the same structure as shown in FIG. 4. Rotation set the Transform node (0,0,1, Pi / 2). 0.04 radius of the cylinder, a height of 0.02. The wheels of color to green.

  3. To be able to drive the wheels, a RotationalMotor added at each hinge joint, and to set their name field "wheel1" (note that not DEF). Named after the name can be used directly in the controller.

d) Adding Sensors

  1. As described above, adding two distance sensors. The robot from the front sensor is an angle vector 0.3
    [RAD]. To their type field is set to "sonar". The graphics and physical shape thereof is set to 0.01 cubic edge length (not transform) [m]. Set their color is blue. Also, give them a set name field.

e) preparation of the controller

  1. To program the rotary electric machine, comprising a first step corresponding to the node API module RotationalMotor: #include <webots / motor.h>

  2. Then initialize RotationalMotor

WbDeviceTag wheels[4];
char wheels_names[4][8] = { 
"wheel1", "wheel2", "wheel3", "wheel4"
for (i=0; i<4 ; i++) wheels[i] = wb_robot_get_device(wheels_names[i]);
}
  1. Motor may be driven by a motor set position, velocity, acceleration or force (see the Reference Manual). Here we are interested in setting its speed.
double speed = -1.5; // [rad/s] 

wb_motor_set_position(wheels[0], INFINITY); 

wb_motor_set_velocity(wheels[0], speed);

   
  1. Note that, lookupTable DistanceSensor field sensor which indicates the value of the node (see the Reference Manual) returns.

. V reference procedure is as follows:

#include <webots/robot.h>

#include <webots/motor.h>

 

#define TIME_STEP 64

 

int main(int argc, char **argv) {
  wb_robot_init();
  WbDeviceTag wheels[4];
  char wheels_names[4][8] = {
   "wheel1", "wheel2","wheel3", "wheel4"
 };
  int i;
  for (i=0; i<4 ; i++)
    wheels[i] = wb_robot_get_device(wheels_names[i]);
  double speed = 1.5; // [rad/s]
  for (i=0; i<4 ; i++)
  {
    wb_motor_set_position(wheels[i], INFINITY);
    wb_motor_set_velocity(wheels[i], speed);
  }
  /* main loop
   * Perform simulation steps of TIME_STEP milliseconds
   * and leave the loop when the simulation is over
   */
while (wb_robot_step(TIME_STEP) != -1) {
    /*
     * Read the sensors :
     * Enter here functions to read sensor
data, like:
     * double val = wb_distance_sensor_get_value(my_sensor);
     */
    /* Process sensor data here */
    /*
     * Enter here functions to send actuator
commands, like:
     * wb_motor_set_position(my_actuator,
10.0);
     */
  };
  /* Enter your cleanup code here */
  /* This is necessary to cleanup webots
resources */
  wb_robot_cleanup();
  return 0;
}

result

Released seven original articles · won praise 3 · Views 739

Guess you like

Origin blog.csdn.net/weixin_38172545/article/details/105391804