We'll control a four wheel robot with a camera (one that we made in the previous page) and see in depth how everything is working out. We'll create everything from scratch here (even the packages). Since there's so much to do, I'll just give information in brief about the codes and procedures. You'll also see how to go about a project in ROS, so there's plenty of practical knowledge to be gained.
We'll call the robot fwb and thus the packages can be named fwb_description for the robot description and fwb_gazebo for Gazebo simulator.
Run the following commands on a terminal:
cd ROS_workspaces/ros_ws/src/
catkin_create_pkg fwb_description robot_state_publisher tf urdf xacro
catkin_create_pkg fwb_gazebo gazebo_ros
Then, make your workspace (not always necessary, but good to see if there are any existing problems)
cd ~/ROS_workspaces/ros_ws/
catkin_make
We'll use the same robot description file that was used in the previous tutorial with the same Gazebo tags as well. We'll just make a few additions to the Robot Description to support a controller in Gazebo.
After that, make the following amendments to accommodate for the controller plugin, do these in the Gazebo file (four_wheel_bot.gazebo):
We'll create the RViZ file by the following process:
roscore
rosrun rviz rviz
This launch file is named "GazeboGUI.launch" and is placed in a folder named launch in package fwb_gazebo.
This launch file is named "SpawnRobotGazebo.launch" and is placed in a folder named launch in package fwb_gazebo.
This launch file is named "RobotRViZ.launch" and is placed in a folder named launch in package fwb_description.
There's another launch file made to inspect the robot model (named "XACROLauncher.launch") and it is placed in a folder named launch in package fwb_description. This launch file won't be used in the final stage, it's just to debug and see how to robot model development is going on.
To run everything, we'll run the following commands on different terminals (or different tabs):
roslaunch fwb_gazebo GazeboGUI.launch
roslaunch fwb_gazebo SpawnRobotGazebo.launch
roslaunch fwb_description RobotRViZ.launch
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
sudo apt install ros-melodic-teleop-twist-keyboard
to install it and then try again. You can actually put this as a node under the launch file that spawns the robot model in gazebo.rosrun rqt_graph rqt_graph
Some images taken during runtime are shown below
Gazebo GUI with the model spawned in the background and the teleop_twist_keyboard node running in the foreground (selected and active window). The node controls the robot movement in the Gazebo environment and the simulator simulates everything and shows the results.
RViZ GUI in the background showing the camera feed in the bottom left corner, this one was taken at a different moment
Everything that was spawned (without the rqt_graph node)
ROS Computation graph shown by running the rqt_graph node. Note that I've unchecked Debug and tf under Hide options on the top. Notice the roles played by the following nodes:
You can play around with everything like mode items, have collisions in Gazebo and see how the physics simulator goes along. I'd also suggest using different physical parameters and seeing which one fits the real world best.
Woah...
Oops...