Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Remote Keyboard Control

tanyax edited this page Jun 20, 2017 · 7 revisions
  • In each of the following terminals, SSH into the TK1 and source the setup.bash file

    1. roscore
    2. rosrun rosserial_python serial_node.py /dev/ttyACM0 (this is what allows us to talk to the teensyduino)
    3. rosrun week1tutorial talker.py
    4. rosrun week1tutorial keyboard.py
  • Use the arrow keys (while in the keyboard.py terminal) to control the car. Use the 'backspace' key as an e-brake. Hit 'q' to quit the keyboard.py program. For all other programs (in the other terminals), CTRL-C will quit their applications.

  • Optional: open another terminal and run rostopic echo /drive_pwm to view the PWM values being sent to the teensyduino (and subsequently to the low-level motor controllers). This can be used to confirm any app is sending correct commands to the wheels, even when the motors are powered off. This testing technique should be used in initial development to ensure the car won't run itself into walls or off tables.


Breaking down the code for the keyboard application:

Messages

  • Two primary message types:

    1.drive_param: (float32) velocity, angle

    2.drive_values: (int16) pwm_drive, pwm_angle

  • drive_param is published on the drive_parameters topic (from keyboard to talker)

  • drive_values is published on the drive_pwm topic (from talker to Teensy)

  • drive_values can only take on integer values [0,2^16], but we restrict it further to [6554,13108], which is the range of values we experimentally determine is appropriate to drive the car (i.e. values corresponding to the appropriate min/max velocity and angle)

  • drive_param can take on any values we choose, but if we don't standardize this range, we must be careful to use this message type consistently across different pieces of code and packages.

    • In the F1/10 tutorials, they use [-100.0,100.0] as the range. But last semester, I changed it to [9480,10080] (pwm vals, essentially) for velocity values and [-10,10] for steering.

    • Currently talker.py serves as the "translator" between the two messages types (mapping from one range of values to the appropriate pwm range of values).

  • Nicole's tested values for PWM (should re-evaluate):

    • Stop range: [9560,10000], use 9780 as the stop value

    • Forward range: [10000,10080]

    • Reverse range: [9480,9560]

Teensy Specifics

  • Arduino structure consists of a setup function and main loop. Use setup to initialize stuff. Use the main loop to call the ROS node spinOnce() function (which will process the next message in the queue and call the corresponding callback function). These callback functions should be defined outside of these Arduino setup/loop blocks.

  • We use the Teensyduino purely to output a PWM signal. Hence the critical functions we call are analogWrite_(). These functions will set up how our PWM signal looks.

  • Everytime a drive_values message is received, the PWM signal's duty cycle will be adjusted according the the message's values. Note the duty cycle will not change until another analogWrite(). Hence, the angle pwm signal remains at this new duty cycle until the next incoming message. However, I modified the code so that an additional timer would reset the velocity pwm signal duty cycle to the "stop" value.