Ask Your Question
0

kobuki_keyop, keyop.launch

asked 2014-11-06 09:14:20 -0500

Kuniaki Saito gravatar image

updated 2014-11-09 21:03:53 -0500

Mehdi. gravatar image

roslaunch kobuki_keyop keyop.launch I want to write a python code to replace keyop.launch. However, it doesn't go well. I think it is wrong with the way to send the message of keyboardinput. How can I solve the problem. I can compile the code. Please help me.

import roslib; roslib.load_manifest('kobuki_keyop')

from kobuki_msgs.msg import KeyboardInput

import rospy

#import KeyboardInput                                                          

from std_msgs.msg import String

#from geometry_msgs.msg import Twist                                           

def key():

 rospy.init_node("keyop")

 pub1 = rospy.Publisher("keyop/motor_power",KeyboardInput)

 pub1 = rospy.Publisher("mobile_base/commands/motor_power",KeyboardInput)

 pub2 = rospy.Publisher("keyop/cmd_vel",KeyboardInput)

 while not rospy.is_shutdown():

  str = KeyboardInput()

  linear_vel = KeyboardInput()

  angular_vel = KeyboardInput()

  print str

  pub1.publish(linear_vel)

  pub2.publish(angular_vel)

  rospy.sleep(1.0)

  rospy.spin()

if __name__ == '__main__':
     key()
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2014-11-09 21:12:25 -0500

Mehdi. gravatar image

you don't seem to have any keyboard callback function. linear_vel = KeyboardInput() will not take your keyboard input. If you check the cpp implementation of Kobuki teleop you can see that there is a function dedicated to detecting the user's input. For simplicity you could use cv2.WaitKey function from openCV in your code instead.

Here is the keyboard input detection function from cpp

void KeyOpCore::keyboardInputLoop()
{
struct termios raw;
memcpy(&raw, &original_terminal_state, sizeof(struct termios));
raw.c_lflag &= ~(ICANON | ECHO);
// Setting a new line, then end of file
raw.c_cc[VEOL] = 1;
raw.c_cc[VEOF] = 2;
tcsetattr(key_file_descriptor, TCSANOW, &raw);
puts("Reading from keyboard");
puts("---------------------------");
puts("Forward/back arrows : linear velocity incr/decr.");
puts("Right/left arrows : angular velocity incr/decr.");
puts("Spacebar : reset linear/angular velocities.");
puts("d : disable motors.");
puts("e : enable motors.");
puts("q : quit.");
char c;
while (!quit_requested)
{
if (read(key_file_descriptor, &c, 1) < 0)
{
perror("read char failed():");
exit(-1);
}
processKeyboardInput(c);
}
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-11-06 09:14:20 -0500

Seen: 361 times

Last updated: Nov 09 '14