Using joy topic to increase/decrease a variable's value continuously [closed]

asked 2015-03-01 17:24:59 -0500

rbaleksandar gravatar image

Hi :)

I've just started learning ROS and want to use it for a project of mine at the university. One of the things I'd like to do is to use a joystick to control a cute little KUKA KR3 CR robot using an inverse kinematics cpp file generated by OpenRAVE. I've looked into the example in the ROS wiki about controlling a turtle with a joystick and got it up and running in no time. My configuration is:

  • Host: Debian 7.0 Wheezy 64bit
  • VirtualBox Guest: Lubuntu 12.04 with ROS Hydro
  • Joystick Logitech Attack 3

I'm using a VirtualBox since 1)installing ROS on Debian proved to be a pain in the butt (at least for me) and 2)I like keeping thing separate so that I can possibly transfer my virtual machine to my working PC once I go to the lab in a couple of days. Here is how things are supposed to work:

  1. Joy_node publishes a joy message
  2. My node (let's call it JoyControl_node) has subscribed to the topic and receives joy messages
  3. These messages are processed accordingly and the movement of my stick + pressing some of the buttons generates a Transformation message looking like this:

    std_msgs/Header header

    float32[3] translationXYZ

    float32[3] rotationXYZ

  4. JoyControl_node publishes the Transformation message

  5. ...

Taking into account the movement of the stick and also a bunch of buttons (sadly the stick has only 2 DoF, which I can only map to either translation along or rotation around two axes so I have to map some of the translation and rotation to the buttons of the joystick) I increase/decrease/don't change at all a set of translations (X,Y and Z) and rotation (around X, Y and Z). These are supposed to be the Cartesian coordinates of a point including its orientation. Note that I do realize that I have to do some additional checking if the coordinates are plausible but this will be done in another node, which uses the inverse kinematics by OpenRAVE. For now just imagine that the results produced here are useful. ;)

The issue I'm having is that I can't figure out how to make the change (increase/decrease of the value of my 6 variables) continuous. Here is my code (read about the TODO after the code section):

#include <ros/ros.h>
#include <sensor_msgs/Joy.h>
#include <JoyControl_node/Transformation.h>

class TeleopTransformation
    void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
    ros::NodeHandle nh;
    float transX, transY, transZ;
    float rotX, rotY, rotZ;
    ros::Subscriber joy_sub;
    ros::Publisher transformation_pub;


  : transX(0), transY(0), transZ(0)
  , rotX(0), rotY(0), rotZ(0)
  joy_sub = nh.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopTransformation::joyCallback, this);
  transformation_pub = nh.advertise<JoyControl_node::Transformation>("teleop_transformation/point", 1);

void TeleopTransformation::joyCallback(const sensor_msgs::Joy::ConstPtr &joy)
  JoyControl_node::Transformation tmsg;

  // ROS_DEBUG_STREAM("axis 0: " << joy->axes[0] << "\naxis 1:" << joy->axes[1] << "\naxis 2:" << joy->axes[2]);

  // TODO convert movement of the axes to Cartesian coordinates and ...
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2018-01-11 20:12:42.071522