PID configuration and Adding colours.....
Previously on this page...…
- We assembled the robot and launched it in gazebo and Rviz.
- We understood Each file generated by URDF exporter.
- We added plugin to urdf and controlled our robot with which we finished first stage of our project.
Adding Colors...…
- So lets make our sad robot happy, by adding colours๐, as I mentioned in previous post that stl file format doesn't support color and textures, we can add colors by two methods either by add colors in urdf or replacing stl files with dae files.
- I have tried both of them but I will recommend you to go by urdf method and in this post we will be doing the same , replacing stl with dae is little bit tedious job we will do in future.
- So lets get started, open your favorite text editor, if you are using dual boot or vm ware and if using wsl go for vscode and if you are using on windows open in vs code only.
- open pnp_bot folder and open material.xacro file, you will find only one material tag which is silver copy paste it down and change the name of material to which you want to and also change RGBA values here is mine file:
- you can copy this same, and navigate to pnp_bot.xacro and in material tag change the name to which you have generated in materials file, eg: under base_link in materials tag replace silver with wood, and so on you can change for each and every part.
- now press "ctrl+shift+~" to open vs code integrated terminal and launch Rviz, by typing roslaunch pnp_bot_description display.launch, you can notice that colors are added to robot.
- exit the Rviz and launch gazebo by typing the same command and just replacing display with gazebo, you will find that colours aren't add to robot in gazebo, this is because gazebo doesn't consider colours give by urdf it follows ORGE scripts for color and textures, hence we need to have changes in gazebo file.
- now open pnp_bot.gazebo file and copy paste the xacro property tag down and change the name and value for different materials, take a look at list of materials in gazebo, and change the value accordingly, here is my file :
- Also after adding these tags make sure to change the values in material tag inside each gazebo tag, then save and relaunch the robot in gazebo.
- now the robot should be launched with color now lets se how we can control the joints of robot.
PID tuning and controlling the joints...…
- now if robot is launched with colors in gazebo lets start controlling the joint of robot, now if you are following the blogs you will be knowing that joint control can be achieved by launching controller launch file.
- don't kill the previous terminal and if have killed, then relaunch the file and in new terminal type the roslaunch command and replace gazebo.launch with controller.launch, one tip I want to give is that if you don't know the full command or are lazy at typing the just press <tab> to complete the command and to get commands starting from same initials press <tab><tab>.
- as long as I know you will encounter this error:
- Actually this is not error but it's warning that gazebo_ros is unable to launch the controllers, and on left side you can notice some building in background of robot I have add environment to the world, we will do this in next post.
- to solve this problem navigate to controller.yaml file and remove the controller part of name, i.e. change the name pnp_bot_controller to pnp_bot.
- now copy this name and navigate to pnp_bot.gazebo file and in plugin tag having name control remove forward slash "/" and bellow that line add: "<robotNamespace>/<the name you have copied></robotNamespace> </plugin>"
- and also in every xacro file check that the name of robot in robot tag is same as you have copied, also go to controller.launch file and in first node tag which controller spawner change the value of "ns" argument to which you have copied.
- Also go to gazebo.launch file in "arg" tag of pause change the value to false, so that simulation is not paused when gazebo is launched.
- now try and launch the robot in gazebo by using roslaunch command and in another terminal launch controller.launch file as soon as controllers are loaded try to find the robot in gazebo, I bet you, can't find it๐, when I launched for first time even I was not able to spot it, later I found it by right clicking on pnp_bot under model section on left side and clicking on follow button, here I found it๐๐:
- why this happened can you find this, let me point out as we are using controllers PID default value must be zero before deploying them else the robot can have any random motion due to untuned values of PID, lets understand these terms and tune them.
- So, what are PID controllers, these are controller which try and reduce the error in control system by using the values of proportional-integral-differential gains.
- Meaning that we pass value to joint and by any cause it is not able to achieve the goal then the PID controller will try to reduce the error in published value and current values, to know more about PID controllers click here , you must read fundamental operation section on the page to know the working.
- Also go through loop tuning section, as we will be tuning the controllers now.
- now lets start tuning PID controller, first go to controller.yaml file and change all p,i,d values to zero so that robot will not start dancing again๐.
- now kill the master and gazebo terminals if still running and after making the above changes relaunch gazebo and controllers and run the below commands each in new terminal:
- rosrun rqt_publisher rqt_publisher
- rosrun rqt_reconfigure rqt_reconfigure
- rosrun rqt_plot rqt_plot
- and it will launch 3 more windows and if you have completed beginner tutorials you might be familiar with rqt.
- Feel free to decorate the windows as below and watch video to have a glimpse what we will be doing next:
- so does it gives developer role vibes??๐ in which we have to look at multiple windows at same time, lets have look at what I am doing here.
- First rqt_publisher, it will help you to publish data to specific joint you will not find the pnp_bot.... bar you have to select it, go to topic section on top left, expand it and choose the topic similar to which I have in my case Rev27 is joint for arm.
- Choose the joint which is corresponding to your robots arm and also select the topic which ends with "/command", so in my case its /pnp_bot/Rev27_joint_controller/command in your case it will be /robot name/joint-name_joint_controller/command, and on right side there is "+" button click on it to add the topic also feel free to change the freq. value to which ever you wish.
- Second, rqt_reconfigure, it will help you in changing the PID values in real time i.e. you can change the values and see which is the best, in this window on left side click on the pid under the joint to which we will be publishing.
- like in video I was changing the values and found the optimal value you have to do this for every joint except the joints of wheels as they are controlled by gazebo plugins.
- Third, rqt_plot, it will plot the values, in video you can see the two topics which I am plotting one is command and other is state/process_value which will show what is state of joint at any point its like a feedback.
- now after these things are set now before changing any pid value first publish the data and then increase the value of p-gain slightly and se what is the feedback in plot and simulation.
- then increase the value of i and d gain as well but in less amount, if you have gone through loop tuning section on wiki page which I mentioned in above section feel free to follow any of the tuning method and tune the values until you get satisfactory result.
- now we have to do this process for each and every joint except wheel joints, and trust me this job is much tedious than any other we will be accomplishing during this project.
- Now complete this process for all joint and feel free to comment below and fill the contact form if you encounter any problem or error.
Upcoming...…
- Building custom world and environment for the robot.
- writing the script for publishing data to joints.
- Completing the pick and place operation manually in custom world and ending the first version of project.
- One announcement is there that, next blog will be published on Monday or Tuesday you may need break for digestion of the knowledge and tuning the PID gains till then stay tuned.



Comments
Post a Comment