/tankbotROS

An intro to ROS using a RPi, python, tank kit and ultrasonic sensor

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

tankbotROS

An intro to ROS using a tank kit, RPi and ultrasonic sensor. alt_tag

Setup


  1. clone the repo
git clone git@github.com:joemcmanus/tankbotROS.git

1b. If you have not installed ROS yet do the following

joe@tankbot:~$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
joe@tankbot:~$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
joe@tankbot:~$ sudo apt install ros-melodic-ros-base
joe@tankbot:~$ sudo rosdep init 
joe@tankbot:~$ rosdep update 
joe@tankbot:~$ echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
joe@tankbot:~$ source ~/.bashrc
joe@tankbot:~$ sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
  1. Setup workspace
joe@tankbot:~$ mkdir -p tankbot_ros_ws/src
joe@tankbot:~$ cd tankbot_ros_ws/src
joe@tankbot:~/tankbot_ros_ws/src$ catkin_init_workspace 
joe@tankbot:~/tankbot_ros_ws/src$ catkin_create_pkg tankbot_ros rospy std_msgs 
  1. Create Package
joe@tankbot:~/tankbot_ros_ws/src$ cp ~/tankbotROS/ROS/* tankbot_ros/src/. 
joe@tankbot:~/tankbot_ros_ws/src$ cd ~/tankbot_ros_ws/
joe@tankbot:~/tankbot_ros_ws$ catkin_make 
  1. Enable i2c and GPIO without running as root
sudo usermod -aG i2c,dialout joe

  1. Test

You will need 4 terminals to make this work.

  • Log in and run roscore
joe@tankbot:~$ roscore 
... logging to /home/joe/.ros/log/2c987dd4-5f52-11ea-b4f2-b827eb2ffb14/roslaunch-tankbot-7884.log
Checking log directory for disk usage. This may take awhile.
  • Log in and launc the distance sensor/ping_node
joe@tankbot:~/tankbot_ros_ws$ cd ~/tankbot_ros_ws/
joe@tankbot:~/tankbot_ros_ws$ source devel/setup.bash 
joe@tankbot:~/tankbot_ros_ws$ rosrun tankbot_ros ping_node 
  • Log in and launch the driver_node
joe@tankbot:~/tankbot_ros_ws$ cd ~/tankbot_ros_ws/
joe@tankbot:~/tankbot_ros_ws$ source devel/setup.bash 
joe@tankbot:~/tankbot_ros_ws$ rosrun tankbot_ros driver_node 

  • Log in to terminal 4 and test the app, note it is a #1 not a lowercase L.
joe@tankbot:~$ rostopic pub -1 /command std_msgs/String "Forward"
joe@tankbot:~$ rostopic pub -1 /command std_msgs/String "Backward"

Flask


alt_tag

A flask app to drive the robot can be run by starting the 2 step3 above and for step three running python server.py

Since it will be wireless driving around, I would lunch the above commands in screen sessions in case your terminal drops.

Ros Topics


The robot is driven using the ROS topic /command and the distance is monitored using the topic /ping. alt_tag

Parts


alt_tag

This kit was built using the following off the shelf parts:

Standalone


If you want to make the robot standalone you will want to make it a WiFi AP and then you can go beyond WiFi range.

Install wifi-ap snap.

sudo snap install wifi-ap 

Then you may want to start up the above processes on boot.

crontab -e
@reboot /home/you/yourScript.sh 

Create a script that will start roscore, source the env file, start up the tankbot topic and then start flask. An exmaple of one I use is attached here as rosStart.sh .