how to send a message?
Hello, I'm Furuike.
I made a program that control turtlebot.
But the program does not work although its publications, subscriptions, services and connections are the same as keyop (package : kobuki_keyop file name : keyop.launch).
Could you tell me what is the problem with my program?
This is my program.
#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <kobuki_msgs/MotorPower.h>
#define UP 0x48 /* ↑ */
#define DOWN 0x50 /* ↓ */
#define LEFT 0x4D /* → */
#define RIGHT 0x4B /* ← */
int main(int argc, char** argv){
ros::init(argc, argv, "key");
ros::NodeHandle n1;
ros::NodeHandle n2;
ros::Publisher velocity_pub = n1.advertise<geometry_msgs::Twist>("/mobile_base/commands/velocity", 3);;
ros::Publisher motor_pub = n2.advertise<kobuki_msgs::MotorPower>("/mobile_base/commands/motor_power", 1);
int i;
while (ros::ok())
{
geometry_msgs::Twist msg_velocity;
kobuki_msgs::MotorPower msg_motor;
char ss_velocity;
int ss_motor;
if(getchar()=='e'){
ss_motor = 1;
msg_motor.state = ss_motor;
motor_pub.publish(msg_motor);
}
if(getchar()=='d'){
ss_motor = 0;
msg_motor.state = ss_motor;
msg_velocity.linear.x=0;
msg_velocity.angular.x=0;
msg_velocity.linear.y=0;
msg_velocity.angular.y=0;
msg_velocity.linear.z=0;
msg_velocity.angular.z=0;
motor_pub.publish(msg_motor);
velocity_pub.publish(msg_velocity);
}
if(ss_motor == 1){
switch(getchar()){
case UP : msg_velocity.linear.x += 0.05; break;
case DOWN : msg_velocity.linear.x -= 0.05; break;
case RIGHT : msg_velocity.angular.z += 0.33; break;
case LEFT : msg_velocity.angular.z -= 0.33; break;
}
velocity_pub.publish(msg_velocity);
}
if(getchar()=='q'){
return 0;
}
ros::spinOnce();
}
return 0;
}
And this is the information.
Node [/key]
Publications:
* /rosout [rosgraph_msgs/Log]
* /mobile_base/commands/velocity [geometry_msgs/Twist]
* /mobile_base/commands/motor_power [kobuki_msgs/MotorPower]
Subscriptions:
* /clock [rosgraph_msgs/Clock]
Services:
* /key/set_logger_level
* /key/get_loggers
contacting node http://IMI-T400s:60686/ ...
Pid: 16016
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound
* transport: TCPROS
* topic: /mobile_base/commands/velocity
* to: /gazebo
* direction: outbound
* transport: TCPROS
* topic: /mobile_base/commands/motor_power
* to: /gazebo
* direction: outbound
* transport: TCPROS
* topic: /clock
* to: /gazebo (http://IMI-T400s:48512/)
* direction: inbound
* transport: TCPROS
Can you post the code without any <br> symbols? Also what exactly does not work?
if you do:
do you get something on your console?
I'm sorry. I didn't notice that it start a new line without br if I choose preformatted text.
It return the well formatted reaction if I push two times when I do rostopic echo.