Skip to content

Commit 64d0794

Browse files
committed
publishing works for full data float array
1 parent 4bb4223 commit 64d0794

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

pio_workspace/src/power_ros1_main.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SETUP FOR ROS COMMUNICATION WITH THE POWER BOARD
2222
#include <ros.h>
2323
#include <auv_msgs/ThrusterMicroseconds.h>
2424
#include <std_msgs/Float32.h>
25+
#include <std_msgs/Float32MultiArray.h>
2526

2627
// defines thruster pins
2728
#define BACK_L_PIN 2
@@ -35,8 +36,8 @@ SETUP FOR ROS COMMUNICATION WITH THE POWER BOARD
3536

3637
#define LED_PIN 13
3738

38-
#define ENABLE_VOLTAGE_SENSE true
39-
#define ENABLE_CURRENT_SENSE true
39+
#define ENABLE_VOLTAGE_SENSE false
40+
#define ENABLE_CURRENT_SENSE false
4041

4142
// creates ADCSensors and TMP36 sensor objects
4243
ADCSensors adcSensors;
@@ -70,13 +71,18 @@ std_msgs::Float32 thruster8_current_msg;
7071
std_msgs::Float32 board_temperature_msg;
7172
std_msgs::Float32 teensy_temperature_msg;
7273

74+
std_msgs::Float32MultiArray all_data_msg;
75+
float allData[21];
76+
7377
// creates array of 8 thrusters
7478
Servo thrusters[8];
7579

7680
// signals to push to thrusters
7781
uint16_t microseconds[] = {1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500};
7882
const uint16_t offCommand[] = {1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500};
7983

84+
float thrusterForce = -1.0;
85+
8086
float Bvoltages[2]; // array for 2 battery voltage sensing
8187
float Tcurrents[8]; // array for 8 thrusters current sensing
8288
float boardTemperature;
@@ -99,6 +105,10 @@ void commandCb(const auv_msgs::ThrusterMicroseconds &tc) {
99105
memcpy(microseconds, tc.microseconds, 8 * sizeof(uint16_t));
100106
}
101107

108+
void thruster_force_Cb(const std_msgs::Float32 &tc) {
109+
thrusterForce = tc.data;
110+
}
111+
102112
// attaches and arms thrusters
103113
void initThrusters() {
104114
thrusters[BACK_L].attach(BACK_L_PIN);
@@ -129,6 +139,9 @@ ros::Publisher thruster8_current("/power/thrusters/current/8", &thruster8_curren
129139
ros::Publisher board_temperature("/power/board/temperature", &board_temperature_msg);
130140
ros::Publisher teensy_temperature("/power/teensy/temperature", &teensy_temperature_msg);
131141

142+
ros::Subscriber<std_msgs::Float32> thrusterforcesub("/thruster/force", &thruster_force_Cb);
143+
ros::Publisher alldatapub("/all/data", &all_data_msg);
144+
132145
// senses the battery voltages, thruster currents, and board and teensy temperatures
133146
void senseData() {
134147
float* voltagePtr = adcSensors.senseVoltage();
@@ -182,6 +195,39 @@ void publishData() {
182195
teensy_temperature.publish(&teensy_temperature_msg);
183196
}
184197

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+
185231
// setup all thrusters and sensors and setup node handler for subscribing and advertising
186232
void power_ros1_setup() {
187233
pinMode(LED_PIN, OUTPUT);
@@ -206,13 +252,20 @@ void power_ros1_setup() {
206252
nh.advertise(thruster8_current);
207253
nh.advertise(board_temperature);
208254
nh.advertise(teensy_temperature);
255+
nh.subscribe(thrusterforcesub);
256+
257+
all_data_msg.data_length = 21;
258+
259+
nh.advertise(alldatapub);
209260
}
210261

211262
void power_ros1_loop() {
212263
updateThrusters(microseconds);
213264

214265
publishData();
215266

267+
allDataFunction();
268+
216269
nh.spinOnce();
217270

218271
delay(10);

pio_workspace/src/thruster_tests_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void sensor_setup() {
3535
boolean _tare = true;
3636
LoadCell.start(stabilizingtime, _tare);
3737
if (LoadCell.getTareTimeoutFlag()) {
38-
while (1);
38+
//while (1);
3939
} else {
4040
LoadCell.setCalFactor(calibrationValue);
4141
}

pio_workspace/test/thruster_tests/commands.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DOCKER:
1212
sudo apt update
1313
sudo apt install tmux -y
1414
sudo apt install git -y
15+
sudo apt install vim -y
1516
sudo apt install -y ros-noetic-rosserial
1617
sudo apt install python3-catkin-tools -y
1718
sudo apt install ros-noetic-rosserial-arduino ros-noetic-rosserial -y

0 commit comments

Comments
 (0)