@@ -22,6 +22,7 @@ SETUP FOR ROS COMMUNICATION WITH THE POWER BOARD
22
22
#include < ros.h>
23
23
#include < auv_msgs/ThrusterMicroseconds.h>
24
24
#include < std_msgs/Float32.h>
25
+ #include < std_msgs/Float32MultiArray.h>
25
26
26
27
// defines thruster pins
27
28
#define BACK_L_PIN 2
@@ -35,8 +36,8 @@ SETUP FOR ROS COMMUNICATION WITH THE POWER BOARD
35
36
36
37
#define LED_PIN 13
37
38
38
- #define ENABLE_VOLTAGE_SENSE true
39
- #define ENABLE_CURRENT_SENSE true
39
+ #define ENABLE_VOLTAGE_SENSE false
40
+ #define ENABLE_CURRENT_SENSE false
40
41
41
42
// creates ADCSensors and TMP36 sensor objects
42
43
ADCSensors adcSensors;
@@ -70,13 +71,18 @@ std_msgs::Float32 thruster8_current_msg;
70
71
std_msgs::Float32 board_temperature_msg;
71
72
std_msgs::Float32 teensy_temperature_msg;
72
73
74
+ std_msgs::Float32MultiArray all_data_msg;
75
+ float allData[21 ];
76
+
73
77
// creates array of 8 thrusters
74
78
Servo thrusters[8 ];
75
79
76
80
// signals to push to thrusters
77
81
uint16_t microseconds[] = {1500 , 1500 , 1500 , 1500 , 1500 , 1500 , 1500 , 1500 };
78
82
const uint16_t offCommand[] = {1500 , 1500 , 1500 , 1500 , 1500 , 1500 , 1500 , 1500 };
79
83
84
+ float thrusterForce = -1.0 ;
85
+
80
86
float Bvoltages[2 ]; // array for 2 battery voltage sensing
81
87
float Tcurrents[8 ]; // array for 8 thrusters current sensing
82
88
float boardTemperature;
@@ -99,6 +105,10 @@ void commandCb(const auv_msgs::ThrusterMicroseconds &tc) {
99
105
memcpy (microseconds, tc.microseconds , 8 * sizeof (uint16_t ));
100
106
}
101
107
108
+ void thruster_force_Cb (const std_msgs::Float32 &tc) {
109
+ thrusterForce = tc.data ;
110
+ }
111
+
102
112
// attaches and arms thrusters
103
113
void initThrusters () {
104
114
thrusters[BACK_L].attach (BACK_L_PIN);
@@ -129,6 +139,9 @@ ros::Publisher thruster8_current("/power/thrusters/current/8", &thruster8_curren
129
139
ros::Publisher board_temperature (" /power/board/temperature" , &board_temperature_msg);
130
140
ros::Publisher teensy_temperature (" /power/teensy/temperature" , &teensy_temperature_msg);
131
141
142
+ ros::Subscriber<std_msgs::Float32> thrusterforcesub (" /thruster/force" , &thruster_force_Cb);
143
+ ros::Publisher alldatapub (" /all/data" , &all_data_msg);
144
+
132
145
// senses the battery voltages, thruster currents, and board and teensy temperatures
133
146
void senseData () {
134
147
float * voltagePtr = adcSensors.senseVoltage ();
@@ -182,6 +195,39 @@ void publishData() {
182
195
teensy_temperature.publish (&teensy_temperature_msg);
183
196
}
184
197
198
+ void allDataFunction () {
199
+ allData[0 ] = microseconds[0 ];
200
+ allData[1 ] = microseconds[1 ];
201
+ allData[2 ] = microseconds[2 ];
202
+ allData[3 ] = microseconds[3 ];
203
+ allData[4 ] = microseconds[4 ];
204
+ allData[5 ] = microseconds[5 ];
205
+ allData[6 ] = microseconds[6 ];
206
+ allData[7 ] = microseconds[7 ];
207
+
208
+ allData[8 ] = thrusterForce;
209
+
210
+ allData[9 ] = Tcurrents[0 ];
211
+ allData[10 ] = Tcurrents[1 ];
212
+ allData[11 ] = Tcurrents[2 ];
213
+ allData[12 ] = Tcurrents[3 ];
214
+ allData[13 ] = Tcurrents[4 ];
215
+ allData[14 ] = Tcurrents[5 ];
216
+ allData[15 ] = Tcurrents[6 ];
217
+ allData[16 ] = Tcurrents[7 ];
218
+
219
+ allData[17 ] = Bvoltages[0 ];
220
+ allData[18 ] = Bvoltages[1 ];
221
+
222
+ allData[19 ] = boardTemperature;
223
+
224
+ allData[20 ] = teensyTemperature;
225
+
226
+ all_data_msg.data = allData;
227
+
228
+ alldatapub.publish (&all_data_msg);
229
+ }
230
+
185
231
// setup all thrusters and sensors and setup node handler for subscribing and advertising
186
232
void power_ros1_setup () {
187
233
pinMode (LED_PIN, OUTPUT);
@@ -206,13 +252,20 @@ void power_ros1_setup() {
206
252
nh.advertise (thruster8_current);
207
253
nh.advertise (board_temperature);
208
254
nh.advertise (teensy_temperature);
255
+ nh.subscribe (thrusterforcesub);
256
+
257
+ all_data_msg.data_length = 21 ;
258
+
259
+ nh.advertise (alldatapub);
209
260
}
210
261
211
262
void power_ros1_loop () {
212
263
updateThrusters (microseconds);
213
264
214
265
publishData ();
215
266
267
+ allDataFunction ();
268
+
216
269
nh.spinOnce ();
217
270
218
271
delay (10 );
0 commit comments