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

How to code user inputs and print messages?

asked 2019-02-09 22:35:30 -0600

loguna gravatar image

Hi,

I am new to ROS. I wish to do a program such that a node get input from user (example: please key in 'H' or 'B') and transfer to another node via a topic. That node receive the message and print out ('Hey' ; if H is keyed and 'Bye'; if B is keyed)

May i know how can i program these?

edit retag flag offensive close merge delete

Comments

1

ROS nodes are most commonly written in C++ or Python. You would use the standard way in either of those languages to get input and print output. There are many websites that have beginner tutorials. Here is one list of sites: https://www.codeconquest.com/blog/the...

billy gravatar image billy  ( 2019-02-10 13:52:14 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-02-10 14:40:32 -0600

First if you haven't already done so work through the introductory tutorials including the simple publisher examples in your chosen language (C++ or Python) then you will be ready to start making your specific node.

There are many simple nodes designed for tele-operating robots that use the keyboard which do something very similar. In their case the key presses are used to generate the appropriate geometry_msgs/Twist message. In your case you would want to publish a std_msgs/String message.

If you look at the source code for the turtle_bot_teleop node you can see how it gets key presses and publishes messages. You could use this python code as a starting point if you like, although it is a bit more complicated than what you are building.

Hope this gets you started.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-02-09 22:35:30 -0600

Seen: 1,913 times

Last updated: Feb 10 '19