[ros-users] problems modifying teleop_wiimote tutorial

jovi wap joviwap at gmail.com
Tue Aug 31 12:07:36 UTC 2010


Hello everybody,

I started some days ago to play with ROS and I am having some little
troubles with the teleop_wiimote tutorial (
http://www.ros.org/wiki/wiimote/Tutorials/WritingTeleopNode). I am using
Ubuntu 10.04 and installed ROS from the repository.

The problem is that any change i do in the code does not make any difference
in the behavior of the node. I tried to add button B support to stop the
"simulated turtle" any time i don't press this button but it does not seem
to work.

The launch file looks good. The output for "rostopic list" is:

/imu/data
/imu/is_calibrated
/joy
/rosout
/rosout_agg
/turtle1/color_sensor
/turtle1/command_velocity
/turtle1/pose
/wiimote/leds
/wiimote/nunchuk
/wiimote/rumble
/wiimote/state

And i check the /wiimote/state data though "rostopic echo /wiimote/state"
and it also looks good.

I tried compiling with make and rosmake commands but i didn't get anything
new.

Any ideas?

Best regards.
Jose V. Sogorb

PD: Here is my modified code.

// %Tag(FULL)%
// %Tag(INCLUDE)%
#include <ros/ros.h>
#include <turtlesim/Velocity.h>
#include <joy/Joy.h>
#include <wiimote/State.h>
// %EndTag(INCLUDE)%


// %Tag(CLASSDEF)%
class TeleopTurtle
{
public:
  TeleopTurtle();

private:
  void joyCallback    (const joy::Joy::ConstPtr& joy);
  void buttonsCallback(const wiimote::State::ConstPtr& state);

  ros::NodeHandle nh_;

  bool isReady_;
  int linear_, angular_;
  double l_scale_, a_scale_;
  ros::Publisher vel_pub_;
  ros::Subscriber joy_sub_;
  ros::Subscriber wii_state_;

};
// %EndTag(CLASSDEF)%


// %Tag(PARAMS)%
TeleopTurtle::TeleopTurtle():
  isReady_(false),
  linear_(1),
  angular_(2)
{
  nh_.param("axis_linear", linear_, linear_);
  nh_.param("axis_angular", angular_, angular_);
  nh_.param("scale_angular", a_scale_, a_scale_);
  nh_.param("scale_linear", l_scale_, l_scale_);
// %EndTag(PARAMS)%


// %Tag(PUB)%
  vel_pub_ = nh_.advertise<turtlesim::Velocity>("turtle1/command_velocity",
1);
// %EndTag(PUB)%

// %Tag(SUB)%
  joy_sub_   = nh_.subscribe<joy::Joy>("joy", 10,
&TeleopTurtle::joyCallback, this);
  wii_state_ = nh_.subscribe<wiimote::State>("wiimote/state", 10,
&TeleopTurtle::buttonsCallback, this);
// %EndTag(SUB)%
}

// %Tag(CALLBACK)%
void TeleopTurtle::joyCallback(const joy::Joy::ConstPtr& joy)
{
  turtlesim::Velocity vel;

  if (isReady_)
  {
      vel.angular = a_scale_*joy->axes[angular_];
      vel.linear  = l_scale_*joy->axes[linear_];
  }
  else
  {
      vel.angular = 0;
      vel.linear  = 0;
  }

  vel_pub_.publish(vel);
}

void TeleopTurtle::buttonsCallback(const wiimote::State::ConstPtr& state)
{
    isReady_ = state->buttons[5]; // Button B
    ROS_WARN("The button B value is %d", isReady_);
}
// %EndTag(CALLBACK)%


// %Tag(MAIN)%
int main(int argc, char** argv)
{
  ros::init(argc, argv, "teleop_turtle");
  TeleopTurtle teleop_turtle;

  ros::spin();
}
// %EndTag(MAIN)%

// %EndTag(FULL)%
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/ros-users/attachments/20100831/0d7661fd/attachment-0002.html>


More information about the ros-users mailing list