ROS notes using keyboard to control the movement of models in gazebo

Use the model in the previous note to control the movement with the keyboard in gazebo.
Familiar with ROS communication mode.

After a little time groping and searching for data, we found that there are still many unreasonable places in the model design, such as leg freedom, no specified materials, weight reduction, etc. at present, it is only to be familiar with ROS communication mode, and no gait planning has been learned, so we simplified and fixed some joints, from the 4 degrees of freedom of each leg (hip joint rotates perpendicular to the body, hip joint swings back and forth , the knee joint swings back and forth, and the foot end stretches and slides in the direction of the lower leg), which becomes 2 degrees of freedom (the hip joint swings back and forth, and the foot end stretches and slides in the direction of the lower leg).

There are three feature packs in the workspace.

Where mydog6_description is SolidWorks export URDF folder, and manually added base_link is used to modify the model position and change URDF to xarco. Since the inertia, collision, joint limit, moment and speed attributes have been generated when SolidWorks exports URDF, only gazebo needs to be added_ ros_ Control plug-ins and drives.
Where mydog6_ The dgazebo file realizes the visualization of the model in the gazebo. On the basis of the previous note, it also needs to include a launch file to make gazebo subscribe to the joint position information.

<include file="$(find mydog6_control)/launch/mydog6_control.launch" />

This mydog6_control.launch In mydog6_ Under the launch file of the control function package.


  <!-- Load joint controller configurations from YAML file to parameter server -->
  <rosparam file="$(find mydog6_control)/config/mydog6_control.yaml" command="load"/>
 <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
	output="screen" ns="/mydog6" args="

  <!-- convert joint states to TF transforms for rviz, etc -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
	respawn="false" output="screen">
        <remap from="/joint_states" to="/mydog6/joint_states" />
  <!--node name="position_pub_node" pkg="mydog6_control" type="" respawn="true"/ -->


Where mydog6_control.yaml Content:

 # Publish all joint states -----------------------------------
    type: joint_state_controller/JointStateController
    publish_rate: 100  
  # Position Controllers ---------------------------------------
    type: position_controllers/JointPositionController
    joint: Joint_lf_2
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_rf_2
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_lb_2
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_rb_2
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_lf_4
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_rf_4
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_lb_4
    #pid: {p: 100.0, i: 0.01, d: 10.0}
    type: position_controllers/JointPositionController
    joint: Joint_rb_4
    #pid: {p: 100.0, i: 0.01, d: 10.0}

  Joint_lf_2: {p: 100.0, i: 0.0, d: 10.0}
  Joint_rf_2: {p: 100.0, i: 0.0, d: 10.0}
  Joint_lb_2: {p: 100.0, i: 0.0, d: 10.0}
  Joint_rb_2: {p: 100.0, i: 0.0, d: 10.0}
  Joint_lf_4: {p: 2544.0, i: 0, d: 0.0}
  Joint_rf_4: {p: 2544.0, i: 0, d: 0.0}
  Joint_lb_4: {p: 2544.0, i: 0, d: 0.0}
  Joint_rb_4: {p: 2544.0, i: 0, d: 0.0}

It's ros_control needs to set some parameters, that is, publish joint state, use joint position control and set PID.
Launch gazebo environment: rosslaunch mydog6_ gazebo mydog6_ world.launch
Use rostopic list and info to see that gazebo has subscribed to the topic.

We just need to write the corresponding publisher and send out the joint position information, that is, we can control the movement of the model in gazebo.
To use the keyboard control model, one node 1 is required to publish key information, and one node 2 is required to subscribe to the information of node 1, and publish the corresponding joint information according to the pressed key. Therefore, node 2 has two functions: subscribing to the messages published by the keyboard node and publishing the messages to gazebo.

PID_ The test node is used to adjust the PID and obtain the actual control radian of the joint from the gazebo simulation environment.
I haven't learned gait planning yet, so I use the simplest diagonal gait, which is driven by sine function, and finally I can complete the left and right movements.

Some problems exist:
1.PID regulation:
According to the classical control theory, the system should have definite input and output. For example, to control the position of the sliding joint, the input of the system is the target joint position θ d, and the output is the current joint position θ. Because it is driven by a motor, and the motor itself does not directly identify the position signal, but through the current to control the torque. View Gazebo_ ros_ Src / default in the control plug-in directory_ robot_ Hw_ sim.cpp ´╝îPOSITION_ In the case of PID, the SetForce() interface of Gazebo is called, so the plug-in really takes the force / torque as the action signal.
So the input and output are transformed into the required joint moment signal. When the sliding joint is controlled by P alone, the dynamic equation is approximately: Kp * deviation = inertia force + damping force + gravity. At the beginning, the adjustment was carried out according to the automatic control theory. P used the optimization method and then adjusted I. It was found that the effect was not good. There was clutter in the waveform and "spike" or "jump". After analysis, it is found that it is caused by the structure (the foot end is a sliding joint). The moment of the sliding joint is slightly changed due to the influence of gravity, so there is a deviation. If there is a deviation, it is controlled to make the sliding joint move, so that the position of the center of gravity of the model is slightly changed. The effect of the force brings random vibration of the sliding joint. The longer the extension of the sliding joint, the higher the center of gravity, and the vibration of the sliding joint The greater the swing. It shows that the model will slip due to the vibration of sliding joint in gazebo. In gazebo, the model is overturned, so that the sliding joint does not bear weight (the weight of the body, thigh and other rigid bodies). The control effect is the same as the theory, there is no sudden clutter, and the sliding joint does not vibrate. It can be determined that part of the interference comes from the unreasonable structure. Next, we need to learn theoretical knowledge for analysis and improvement.

2. Through the practice and the inquiry of the relevant literature, it is found that the model design is unreasonable, mainly the foot end sliding joint. This model has four legs and four degrees of freedom for each leg. In fact, many four legs have three degrees of freedom for each leg, respectively, the hip joint is up, down, front and back, and the knee joint is not rotated. Consider improving the model, using SolidWorks to design the structure, using three degrees of freedom per leg instead of sliding joints.

It can be seen from the node graph that it is not complicated to make the model move. Through this simple practice, I am familiar with the preparation of the model. Besides handwriting, I can also export it through SolidWorks, I am familiar with the construction of the simulation environment, and I realize the control of the model by using the native topic communication mode of ROS. ROS is a very good tool, with a good communication framework, it can build a simulation platform for us to verify some ideas, to achieve a model simulation involves many aspects, programming ability is just one of them. Theoretical knowledge is also very important. For example, diagonal gait is driven by simple sin, but due to the lack of theoretical support, it is more often debugging, imagining the state of motion with the brain, and trying to make the model move more. In the next period of time, we need to learn some theoretical knowledge of kinematics. If we increase the joint freedom, we may also need to design the gait planning and find the inverse kinematics solution. Hurry up and read more.
I don't understand gazebo very well, and I don't know if the parameter configuration is correct. I will spend time running the gazebo tutorial completely again.

Tags: Programming

Posted on Fri, 05 Jun 2020 02:42:29 -0700 by ScubaDvr2