array_test.cpp
Go to the documentation of this file.
1 //#define COMPILE_ARRAY_CODE_RSOSSERIAL
2 #ifdef COMPILE_ARRAY_CODE_RSOSSERIAL
3 
4 /*
5  * rosserial::geometry_msgs::PoseArray Test
6  * Sums an array, publishes sum
7  */
8 #include "mbed.h"
9 #include <ros.h>
10 #include <geometry_msgs/Pose.h>
11 #include <geometry_msgs/PoseArray.h>
12 
13 
15 
16 bool set_;
17 DigitalOut myled(LED1);
18 
19 geometry_msgs::Pose sum_msg;
20 ros::Publisher p("sum", &sum_msg);
21 
22 void messageCb(const geometry_msgs::PoseArray& msg) {
23  sum_msg.position.x = 0;
24  sum_msg.position.y = 0;
25  sum_msg.position.z = 0;
26  for (int i = 0; i < msg.poses_length; i++) {
27  sum_msg.position.x += msg.poses[i].position.x;
28  sum_msg.position.y += msg.poses[i].position.y;
29  sum_msg.position.z += msg.poses[i].position.z;
30  }
31  myled = !myled; // blink the led
32 }
33 
35 
36 int main() {
37  nh.initNode();
38  nh.subscribe(s);
39  nh.advertise(p);
40 
41  while (1) {
42  p.publish(&sum_msg);
43  nh.spinOnce();
44  wait_ms(10);
45  }
46 }
47 #endif
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle nh
Definition: ADC.cpp:31
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
XmlRpcServer s
ros::Publisher p("adc",&adc_msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int i
int main()
Definition: ADC.cpp:46


rosserial_mbed
Author(s): Gary Servin
autogenerated on Mon Jun 10 2019 14:53:26