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

publish array velocities in a topic?

asked 2015-04-29 05:35:15 -0500

Alvaro Salcedo gravatar image

Hi Ros users! I have just done a .cpp wich publish velocities in a opic (p3dx/cmd_vel) Here it is:

int main(int argc, char **argv)
{
  ros::init(argc, argv, "lanzando_vel");
  ros::NodeHandle n;
  ros::Publisher vel_pub_ = n.advertise<geometry_msgs::Twist>("p3dx/cmd_vel", 1);

  while (ros::ok())
  {
  geometry_msgs::Twist cmd;
  cmd.linear.x = 0;
  cmd.linear.y = 0;
  cmd.linear.z = 0;

  cmd.angular.x = 0;
  cmd.angular.y = 0;
  cmd.angular.z = 0;
    vel_pub_.publish(cmd);
  }
    return 0;
}

I would like to publish an array velocities, for example:

at 1seg ==> cmd.linear.x=1 at 3 seg==> cmd.linear.x=4 . . .

how can I do that?

Thank you so much!

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2015-04-29 09:05:05 -0500

marguedas gravatar image

Hi, You can create your own message Velocity array. Then you fill your array with twist messages. Finally you publish it.
You have an example in python in this answer.

edit flag offensive delete link more
1

answered 2015-04-30 23:00:53 -0500

130s gravatar image

Although I haven't done it personally, I would try using TwistStamped, put its instances into an array (as @marguedas does in the link provided), particularly when you want to specify the timing where the Twist gets executed. You can specify it in its header.stamp.

edit flag offensive delete link more
0

answered 2015-07-13 06:27:01 -0500

Alvaro Salcedo gravatar image

Hi. First of all thanks for your responses Did you do this @130s ?

I am trying it. I have done this:

  geometry_msgs::Twist cmd;
  geometry_msgs::TwistStamped tiempo;
  cmd.linear.x = 1; 
  cmd.linear.y = 0;
  cmd.linear.z = 0;

  tiempo.header.stamp=5;
  cmd.angular.x = 0;
  cmd.angular.y = 0;
  cmd.angular.z = 4;
  vel_pub_.publish(cmd);

But when it is compiled i can see these errors on terminal

>     /home/alcor/catkin_ws/src/lanzar_velocidades/src/arrayvel.cpp:52:3:
> error: ‘geometry’ has not been
> declared geometry::TwistStamped
> tiempo; ^
> /home/alcor/catkin_ws/src/lanzar_velocidades/src/arrayvel.cpp:52:26:
> error: expected ‘;’ before ‘tiempo’
>     geometry::TwistStamped tiempo; ^ /home/alcor/catkin_ws/src/lanzar_velocidades/src/arrayvel.cpp:57:3:
> error: ‘tiempo’ was not declared in
> this scope tiempo.header.stamp=5;
>     ^ make[2]: * [lanzar_velocidades/CMakeFiles/arrayvel_node.dir/src/arrayvel.cpp.o]
> Error 1 make[1]: *
> [lanzar_velocidades/CMakeFiles/arrayvel_node.dir/all]
> Error 2

Any ideas?

Thanks!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-29 05:35:15 -0500

Seen: 764 times

Last updated: Jul 13 '15