Keyboard Teleop settings.
I write a program in arduino. i want to do the same with ros-keyboard_teleop. can sombody guide me ?any tutorial link.
void setup()
{
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
char data = Serial.read();
if(data == 'i')
{
digitalWrite(24, LOW);
digitalWrite(25, HIGH);
Serial.println("reverse");
}
else if(data == 'j')
{
digitalWrite(24, HIGH);
digitalWrite(25, LOW);
Serial.println("forward");
}
else
{
digitalWrite(24,LOW);
digitalWrite(25,LOW);
Serial.println("stop");
}}}
i did a program. but i think there is a problem with
else if (y = vel.linear.y - 1.0) can you check my code and tell me where is the problem?
#include <ros.h>
#include <geometry_msgs/Twist.h>
float x;
float y;
ros::NodeHandle nh;
void velCallback( const geometry_msgs::Twist& vel)
{
if (x = vel.linear.x - 1.0) //Forward move.
{
digitalWrite(24, LOW);
digitalWrite(23, HIGH);
}
else if (y = vel.linear.y - 1.0) //Backward move
{
digitalWrite(24, HIGH);
digitalWrite(23, LOW);
}
else
{
digitalWrite(24, LOW); //STOP
digitalWrite(23, LOW);
}
}
ros::Subscriber<geometry_msgs::Twist> sub("cmd_vel" , velCallback);
void setup()
{
nh.initNode();
nh.subscribe(sub);
}
void loop()
{
nh.spinOnce();
delay(10);
}
teleop_twist_keyboard
publishes ageometry_msgs/Twist
message type on the/cmd_vel
topic. You should make your arduino subscribe to this. A few other projects that do this are https://sungjik.wordpress.com/tag/ros/ and https://answers.ros.org/question/2585...can you please write how the code should be ? i checked the links.but still dont have idea how to do so.
The code in https://answers.ros.org/question/2585... is how most of the code should be. The only thing you need to add is the digitalWrite commands for your motors in velCallback.
i just updated my program.can you check the code ?i face the problem with y axis.
is this the twist_keboard command
Why do you use Y axis for a backward move ? Y axis is usually for lateral moves, and Z axis of
vel.angular
for turning.Can you explain in the question how your robot moves ? (2 motorized wheels maybe) I think it would help people to understand your needs.
sorry im new to this.i dont know how the code supposed to be.what i want is if i press "i" it should execute first IF condition which is forward move.and if i press any other key whether it is j or k any, it goes backward.