Project

General

Profile

Revision 6499f09b

ID6499f09b560e443f3ec0176b56ca2ab3fc646dd5

Added by Thomas Mullins over 6 years ago

Arduino now reads 2 sonars and publishes

It publishes to /range_up and /range_down, from pins A0 and A1.

View differences:

mikrokopter/arduino/src/main.cpp
5 5
ros::NodeHandle nh;
6 6

  
7 7
std_msgs::UInt16 distance;
8
ros::Publisher range("range", &distance);
8
ros::Publisher range_up("range_up", &distance);
9
ros::Publisher range_down("range_down", &distance);
9 10

  
10 11
void setup()
11 12
{
12 13
  nh.initNode();
13
  nh.advertise(range);
14
  nh.advertise(range_up);
15
  nh.advertise(range_down);
14 16
}
15 17

  
16 18
void loop()
17 19
{
18
  distance.data = 12;
19
  range.publish(&distance);
20
  distance.data = analogRead(0);
21
  range_up.publish(&distance);
22
  distance.data = analogRead(1);
23
  range_down.publish(&distance);
20 24
  nh.spinOnce();
21 25
}

Also available in: Unified diff