ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

ROSJOY help

asked 2014-07-31 09:31:51 -0500

dshimano gravatar image

updated 2014-07-31 13:53:17 -0500

Hi, I'm running hydro on ubuntu 12.04

I have been trying to go through the tutorial on writing a node to use a ps3 controller with ros here. After many try's I think it failed because hydro doesn’t have turtlesim/Velocity.h . I'm a beginner with cs and am not sure how to build this controller node from scratch. in particular, what would I do to this code to get it to work on hydro? Here's the code

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>


class TeleopTurtle
{
public:
  TeleopTurtle();

private:
  void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);

  ros::NodeHandle nh_;

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

};

TeleopTurtle::TeleopTurtle():
  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_);


  vel_pub_ = nh_.advertise<turtlesim::Velocity>("turtle1/turtle1/cmd_vel", 1);


  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 10, leopTurtle::joyCallback, this);

}

void TeleopTurtle::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
  turtlesim::Velocity vel;
  vel.angular = a_scale_*joy->axes[angular_];
  vel.linear = l_scale_*joy->axes[linear_];
  vel_pub_.publish(vel);
}

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

  ros::spin();command_velocity
}

After making two changes, 1) Changing turtlesim_velocity to geometry_msg/Twist 2) Changing Command_Velocity to cmd_vel I get the following errors when running rosmake on the package.

/home/donni/catkin_ws/src/beginner_tutorials/learning_ps3joy/src/turtle_teleop_ps3joy.cpp:44:3: error: ‘turtlesim’ has not been declared /home/donni/catkin_ws/src/beginner_tutorials/learning_ps3joy/src/turtle_teleop_ps3joy.cpp:44:23: error: expected ‘;’ before ‘vel’ /home/donni/catkin_ws/src/beginner_tutorials/learning_ps3joy/src/turtle_teleop_ps3joy.cpp:45:3: error: ‘vel’ was not declared in this scope

Can someone interpret them for me?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2014-07-31 11:39:04 -0500

adreno gravatar image

HI,

1) As of Hydro turtlesim uses the geometry_msgs/Twist message instead of turtlesim/Velocity. 2) Change to cmd_vel instead of command_velocity

So in your code use geometry_msgs/Twist instead of turtlesim/Velocity, Also, publish it to cmd_vel and it should work then.

edit flag offensive delete link more

Comments

Hi, thanks for your help. I made those changes, and got some more errors. I am adding them to my question if you can help me out some more.

dshimano gravatar image dshimano  ( 2014-07-31 13:34:11 -0500 )edit
1

answered 2014-07-31 11:39:22 -0500

updated 2014-07-31 17:06:11 -0500

Swap the turtlesim velocity with geometry_msgs/Twist.

vel_pub_ = nh_.advertise<turtlesim::Velocity>("turtle1/turtle1/cmd_vel", 1); needs to be changed to vel_pub_ = nh_.advertise<geometry_msgs::Twist>("turtle1/turtle1/cmd_vel", 1); turtlesim::Velocity vel; to geometry_msgs::Twist vel; Remove command_velocity at the end.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-07-31 09:31:51 -0500

Seen: 526 times

Last updated: Jul 31 '14