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

oneevening's profile - activity

2015-11-25 09:54:49 -0500 received badge  Famous Question (source)
2015-09-15 00:40:51 -0500 received badge  Famous Question (source)
2015-08-11 15:25:37 -0500 received badge  Notable Question (source)
2015-08-11 09:26:18 -0500 received badge  Popular Question (source)
2015-08-11 06:58:48 -0500 received badge  Editor (source)
2015-08-11 06:57:25 -0500 received badge  Organizer (source)
2015-08-11 06:57:05 -0500 asked a question ROS program controlling arduino via serial communication

I have been working on arduino and ros communication for few days and now I have an arduino code which have two subscribers as;

ros::Subscriber<std_msgs::uint16> sub("red", redLED); ros::Subscriber<std_msgs::uint16> sub2("yellow", yellowLED);

So, when I input "rostopic pub red -r 1 std_msgs/UInt16 1000" it lights up the LED then waits 1 second and turns it off and does that at 1 Hz.

What I want to do is writing a ros code so that when I press up key on keyboard, this rostopic I mentioned above will be sent or the subscriber will be called, however it works.

How can I do that, which topics do I have to look at? Keep in mind that I have no experience with ROS

2015-08-11 06:49:35 -0500 received badge  Notable Question (source)
2015-08-07 11:40:03 -0500 received badge  Popular Question (source)
2015-08-06 10:42:32 -0500 asked a question ROS - Arduino subscriber question

Hello,

I am quite new to ROS but familiar with Arduino. I managed to run the Arduino through ROS. However, I have some questions that I couldn't find the answers for.

I am initializing ROS by typing "roscore" and then establishing the serial communication between arduino and ros by using the "rosrun rosserial_python serial_node.py /dev/ttyUSB0" command. So far so good. Then I send the following command;

rostopic pub red std_msgs/UInt16 1000 which

which calls the "red" function and uses the input of "1000" for delay time. This also works fine. However, when I type this line, it executes only once and there appears a message on the terminal "publishing and latching message. Press ctrl-C to terminate". Meaning that I need to first execute this with keyboard command to be able to input another command.

First of all, I want to send a command and I want this command to run the related function forever unless I send a new command which calls another function and runs it forever. To be able to do that I need those subscribers to return something when they are called or somehow I need to be able to detect they are called so that I can use a simple if else statement in the main loop which serves what I want. Furthermore, I need to get rid of that "publishing and latching message. Press ctrl-C to terminate" message so that I can send another command without cancelling it.

This is what's in my mind and not sure if this is the right way for that framework but appreciate if you show me the way.

#include <ros.h>
#include <std_msgs/UInt16.h>

#define led_y  12
#define led_r  8

ros::NodeHandle  nh;

void yellow(const std_msgs::UInt16& cmd_msg)
{
  digitalWrite(led_y,HIGH);
  delay(cmd_msg.data);
  digitalWrite(led_y,LOW);
  delay(cmd_msg.data); 
}

void red(const std_msgs::UInt16& cmd_msg)
{
  digitalWrite(led_r,HIGH);
  delay(cmd_msg.data);
  digitalWrite(led_r,LOW);
  delay(cmd_msg.data); 
}

ros::Subscriber<std_msgs::UInt16> sub("red", red);
ros::Subscriber<std_msgs::UInt16> sub("yellow", yellow);


void setup()
{
  digitalWrite(MS1, LOW);
  digitalWrite(MS2, LOW);

  nh.initNode();
  nh.subscribe(sub);
}

void loop()
{
  nh.spinOnce();
  delay(1);
}