(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Teleoperation using Joystick

Description: This tutorial covers how to write a teleoperation node and use it to drive the groundbot using arduino.

Keywords: teleoperation, joystick

Tutorial Level: BEGINNER

source : https://github.com/mallasrikanth/joystick_control

$  ls -l  /dev/input

   1 #! /usr/bin/env python
   2 import rospy
   3 from geometry_msgs.msg import Twist
   4 from sensor_msgs.msg import Joy
   5 
   6 # This ROS Node converts Joystick inputs from the joy node
   7 # into commands for turtlesim or any other robot
   8 
   9 # Receives joystick messages (subscribed to Joy topic)
  10 # then converts the joysick inputs into Twist commands
  11 # axis 1 aka left stick vertical controls linear speed
  12 # axis 0 aka left stick horizonal controls angular speed
  13 def callback(data):
  14     twist = Twist()
  15     twist.linear.x = 4*data.axes[7]
  16     twist.angular.z = 4*data.axes[6]
  17     pub.publish(twist)
  18 
  19 # Intializes everything
  20 def start():
  21     # publishing to "turtle1/cmd_vel" to control turtle1
  22     global pub
  23     pub = rospy.Publisher('turtle1/cmd_vel', Twist)
  24     # subscribed to joystick inputs on topic "joy"
  25     rospy.Subscriber("joy", Joy, callback)
  26     # starts the node
  27     rospy.init_node('Joy2Turtle')
  28     rospy.spin()
  29 
  30 if __name__ == '__main__':
  31     start()

Wiki: mallasrikanth/joystick control (last edited 2015-01-04 13:28:41 by mallasrikanth)