Skip to content

Drive Control

EddieCTian edited this page Mar 20, 2021 · 48 revisions

Drive Control Wiki

This page contains instructions for running Drive.

Contents

Running Drive Control Instructions

To Run Drive with joystick using the shell script

First, follow the instructions below for using joystick drive and using the Arduino IDE with ROS.

Then run the following two lines of code:

echo -e "launch_drive() {\n~/catkin_ws/src/rover/scripts/launch_drive.sh\n}" >> ~/catkin_ws/devel/setup.sh
source ~/catkin_ws/devel/setup.sh

Afterwards, launch drive with:

launch_drive

If you want to learn more about the script, add the -h option after the script or check out the source code at ~/catkin_ws/src/rover/scripts/launch_drive.sh.

To Run Drive

Shortcut commands (works on the rsx laptop and the jetson): nvidia (ssh into nvidia) core (start roscore) drive1 (run drive receiver node) drive2 (run drive sender node)

  1. Upload the Drive_receiver Arduino code on the Arduino ssh into the nvidia jetson and run roscore
  2. Run the receiver node in the jetson using this command (***using your port number): rosrun rosserial_python serial_node.py _port:=/dev/ttyACM# _baud:=57600 or drive1
  3. On the separate command window, use this command: rosrun rover drive_sender or drive2
  4. Control the rover using the arrow keys

You might run into an issue with the package "rover" not being found. To fix this, close all your terminals and open a new terminal. Then:

  • (file editor shortcut command) ~/.bashrc

Go to the bottom and type in these lines:

  • source ~/catkin_ws/devel/setup.bash
  • export PYTHONPATH/$PYTHONPATH (not completed)

Adding USB port for Virtual Box Users:

For Virtual box users, the Arduino does not automatically connect to the virtual box and has to be added to the machine. The USB must to forwarded through your computer to the virtual machine. You will know that you need to do this if the ports tab is not accessible when you are trying to change the port.
Follow these steps:

  1. Add the USB to your machine

    • Have the machine in an idle state and click on machine at the top of the page
    • Click on settings
    • Click on the ports option
    • Click on the USB section
    • Check that the USB controller in enabled and that one of the controllers is selected ( the first one 1.1)
    • Click the plus USB icon to check that your USB is being detected and add it to the list
    • Restart the virtual machine and open terminal
  2. Follow the rest of this tutorial to make a vboxusers group on your virtual machine (also included the first set of instructions)

https://www.youtube.com/watch?v=saR-nVRV5rk

  1. If when trying to upload, an error comes out that the permission for the port has been denied then follow this video

https://www.youtube.com/watch?v=mEptke-5rJc

If you don't have rosserial_python installed:

This error results when trying to run drive and you don't have rosserial_python installed. Look at the readME for more information.
Resulting Error: [rospack] Error: package 'rosserial_python' not found

  1. First remove any previous rosserial files that don't say they cannot be removed. Then install the rosserial package using this command: "sudo apt-get install ros-melodic-rosserial-*" (this will install all including the rosserial_python that we need)

  2. Now we can rosrun:
    rosrun rosserial_python serial_node.py _port:=/dev/tty(yourport) _baud:= 57600

Running Joystick Drive

  1. Install the joystick package and configure the joystick: http://wiki.ros.org/joy/Tutorials/ConfiguringALinuxJoystick

  2. Installing the Package sudo apt-get install ros-melodic-joy

Configuring the Joystick

  • ls /dev/input/
    should see jsX (X is a number, usually 0 - this is your joystick)
  • sudo jstest /dev/input/jsX
    move joystick around to test it
  • ls -l /dev/input/jsX
    if XX is rw: the js device is configured properly. if XX is --: the js device is not configured properly and you need to: sudo chmod a+rw /dev/input/js0

Set up the Joy Node

  • roscore
  • rosparam set joy_node/dev "/dev/input/jsX"
  • rosrun joy joy_node
  • In new terminal to test: rostopic echo joy

Using the Arduino IDE with ROS

  • Install Arduino IDE by using this command :
  • sudo apt-get install arduino arduino-core

Install rosserial with these two lines :

  • sudo apt-get install ros-melodic-rosserial-arduino
  • sudo apt-get install ros-melodic-rosserial

Change directory to catkin_ws/src :

Change directory to /home/sketchbook/libraries :

  • rm -rf ros_lib. You can checkout your sketchbook folder through opening Arduino IDE, file, preference
  • run rosrun rosserial_arduino make_libraries.py .
    *** Make sure to include the . at the end of the command

When you open the Arduino IDE, ros_lib should be under File/Examples

If the serialport doesn’t show up, then restart the computer.

To test, upload HelloWorld file from the aruduino ros_lib to the arduino, do roscore, then rosrun rosserial_python serial_node.py /dev/ttyACM# (where # is the port number of the Arduino shown in the Arduino IDE) to run the Arduino as a ROS node

Open another terminal and enter command rostopic echo chatter to see the text message.

*** Set the baud rate to 57600 when using the drive arduino code. (Or when this error shows up: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino)

You can also try directly getting the rosserial library through arduino if it doesn’t show up after this.

Go into sketch, go to include library and click manage libraries. Search for rosserial and click install. Then it should definitely show up.

How to Set Up Joy + Issues

/* For joystick */

After the command "rosrun joy joy_node", if you get the error:

"[ERROR] [1580579912.157133017]: Couldn't open joystick force feedback!
[ INFO] [1580579912.158771272]: Opened joystick: /dev/input/js0. deadzone_: 0.050000. "

just ignore it. It doesn't matter and does not cause any issues.

[To be edited....]
http://wiki.ros.org/joy/Tutorials/ConfiguringALinuxJoystick (Link for initial setup of a linux compatible joystick)

Updated: Installing Arduino IDE (Recommended)

Check this link: https://ubuntu.com/tutorials/install-the-arduino-ide#1-overview
*Note: might need to replace "ACM" with "USB"

PS3 Joystick Key Bindings

The keybindings read from the Joy topic

axes (float values): [left stick {-1.0 when right -- 1.0 when left}, left stick {-1.0 when down -- 1.0 when up}, L2 {-1.0 when pressed -- 1.0 when not pressed}, right stick {-1.0 when right -- 1.0 when left},right stick {-1.0 when down -- 1.0 when up} , R2 {-1.0 when pressed -- 1.0 when not pressed}]

buttons (binary): [X, Circle, Triangle, Square, L1, R1, L2, R2, select, start, power, left joy press, right joypress, up dpad, down dpad, left dpad, right dpad]