NavdataMessageDefinitionsTemplate.c
Go to the documentation of this file.
1 // Autogenerated from source-files using the CreateNavdataFormat.py script
2 
3 #ifdef NAVDATA_STRUCTS_INCLUDES
4 % for item in structs:
5 #include "ardrone_autonomy/${item['struct_name']}.h"
6 % endfor
7 <% included = [] %>\
8 % for item in structs:
9 % for member in item['members']:
10 % if member['include'] not in included:
11 <% included.append(member['include']) %>\
12 #include <${'/'.join(member['include'].split('::'))}.h>
13 % endif
14 % endfor
15 % endfor
16 #endif
17 
18 #ifdef NAVDATA_STRUCTS_HEADER_PUBLIC
19  void PublishNavdataTypes(const navdata_unpacked_t &n, const ros::Time &received);
20 #endif
21 
22 #ifdef NAVDATA_STRUCTS_HEADER_PRIVATE
23 % for item in structs:
24  ros::Publisher pub_${item['struct_name']};
25  bool enabled_${item['struct_name']};
26  ardrone_autonomy::${item['struct_name']} ${item['struct_name']}_msg;
27 % endfor
28 
29  bool enabled_legacy_navdata;
30 
31  bool initialized_navdata_publishers;
32 #endif
33 
34 #ifdef NAVDATA_STRUCTS_INITIALIZE
35  if(!initialized_navdata_publishers)
36  {
37  initialized_navdata_publishers = true;
38 
39  ros::param::param("~enable_legacy_navdata", enabled_legacy_navdata, true);
40  if(enabled_legacy_navdata)
41  {
42  navdata_pub = node_handle.advertise<ardrone_autonomy::Navdata>("ardrone/navdata", 25);
43  imu_pub = node_handle.advertise<sensor_msgs::Imu>("ardrone/imu", 25);
44  mag_pub = node_handle.advertise<geometry_msgs::Vector3Stamped>("ardrone/mag", 25);
45  odo_pub = node_handle.advertise<nav_msgs::Odometry>("ardrone/odometry", 25);
46  }
47 
48  //-------------------------
49 
50 % for item in structs:
51  ros::param::param("~enable_${item['struct_name']}", enabled_${item['struct_name']}, false);
52  if(enabled_${item['struct_name']})
53  {
54  pub_${item['struct_name']} = node_handle.advertise<ardrone_autonomy::${item['struct_name']}>("ardrone/${item['struct_name']}", NAVDATA_QUEUE_SIZE);
55  }
56 
57  //-------------------------
58 
59 % endfor
60  }
61 #endif
62 
63 #ifdef NAVDATA_STRUCTS_SOURCE
64 void ARDroneDriver::PublishNavdataTypes(const navdata_unpacked_t &n, const ros::Time &received)
65 {
66  if(initialized_navdata_publishers)
67  {
68 % for item in structs:
69  if(enabled_${item['struct_name']} && pub_${item['struct_name']}.getNumSubscribers()>0)
70  {
71  ${item['struct_name']}_msg.drone_time = ((double)ardrone_time_to_usec(n.navdata_time.time))/1000000.0;
72  ${item['struct_name']}_msg.header.stamp = received;
73  ${item['struct_name']}_msg.header.frame_id = droneFrameBase;
74 
75 % for member in item['members']:
76 % if member['array_size'] is None:
77  {\
78  ${format_member(item, member, None)}
79  ${item['struct_name']}_msg.${member['name']} = m;
80  }
81 
82 % else:
83  ${item['struct_name']}_msg.${member['name']}.clear();
84  for(int i=0; i<${member['array_size']}; i++)
85  {\
86  ${format_member(item, member, 'i')}
87  ${item['struct_name']}_msg.${member['name']}.push_back(m);
88  }
89 
90 % endif
91 % endfor
92  pub_${item['struct_name']}.publish(${item['struct_name']}_msg);
93  }
94 
95  //-------------------------
96 
97 % endfor
98  }
99 }
100 #endif
101 
102 
103 
104 
105 <%def name="format_member(item, member, i)">
106  ${member['c_type']} c = n.${item['struct_name']}.${member['name']}${'[{}]'.format(i) if i is not None else ''};
107  ${member['ros_type']} m;
108 % if 'matrix33' in member['ros_type']:
109  m.m11 = c.m11;
110  m.m12 = c.m12;
111  m.m13 = c.m13;
112  m.m21 = c.m21;
113  m.m22 = c.m22;
114  m.m23 = c.m23;
115  m.m31 = c.m31;
116  m.m32 = c.m32;
117  m.m33 = c.m33;
118 % elif 'vector21' in member['ros_type']:
119  m.x = c.x;
120  m.y = c.y;
121 % elif 'vector31' in member['ros_type']:
122  m.x = c.x;
123  m.y = c.y;
124  m.z = c.z;
125 % else:
126  m = c;
127 % endif
128 </%def>
bool param(const std::string &param_name, T &param_val, const T &default_val)
#define NAVDATA_QUEUE_SIZE


ardrone_autonomy
Author(s): Mani Monajjemi, Mani Monajjemi
autogenerated on Mon Jun 10 2019 12:39:49