Skip to content

Commit aec2b1a

Browse files
committed
properly init messages
1 parent ff376b5 commit aec2b1a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

pio_workspace/src/power_main.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ void propulsion_microseconds_callback(const void * msgin)
498498
void timer_callback(rcl_timer_t * timer, int64_t last_call_time) {
499499
RCLC_UNUSED(last_call_time);
500500
if (timer != NULL) {
501-
RCSOFTCHECK(rcl_publish(&power_batteries_voltage_publisher, &power_batteries_voltage_publisher, NULL));
501+
RCSOFTCHECK(rcl_publish(&power_batteries_voltage_publisher, &power_batteries_voltage_msg, NULL));
502502
RCSOFTCHECK(rcl_publish(&power_thrusters_current_publisher, &power_thrusters_current_msg, NULL));
503503
RCSOFTCHECK(rcl_publish(&power_board_temperature_publisher, &power_board_temperature_msg, NULL));
504504
RCSOFTCHECK(rcl_publish(&power_teensy_temperature_publisher, &power_teensy_temperature_msg, NULL));
@@ -549,7 +549,7 @@ bool create_entities()
549549
"/power/teensy/temperature"));
550550

551551
// create timer,
552-
const unsigned int timer_timeout = 100;
552+
const unsigned int timer_timeout = 1000;
553553
RCCHECK(rclc_timer_init_default(
554554
&timer,
555555
&support,
@@ -615,18 +615,47 @@ void power_setup() {
615615
set_microros_serial_transports(Serial);
616616
delay(2000);
617617

618+
// allocates correct message sizes and initialzies to 0, required or crashes
619+
618620
propulsion_microseconds_msg.data.size = 8;
619621
propulsion_microseconds_msg.data.capacity = 8;
620622
propulsion_microseconds_msg.data.data = (int16_t*)malloc(propulsion_microseconds_msg.data.capacity * sizeof(int16_t));
623+
for (int i = 0; i < 8; i++) {
624+
propulsion_microseconds_msg.data.data[i] = 0;
625+
}
621626

622627
power_batteries_voltage_msg.data.size = 2;
623628
power_batteries_voltage_msg.data.capacity = 2;
624629
power_batteries_voltage_msg.data.data = (float*)malloc(power_batteries_voltage_msg.data.capacity * sizeof(float));
630+
for (int i = 0; i < 2; i++) {
631+
power_batteries_voltage_msg.data.data[i] = 0.0;
632+
}
633+
634+
power_thrusters_current_msg.data.size = 8;
635+
power_thrusters_current_msg.data.capacity = 8;
636+
power_thrusters_current_msg.data.data = (float*)malloc(power_thrusters_current_msg.data.capacity * sizeof(float));
637+
for (int i = 0; i < 8; i++) {
638+
power_thrusters_current_msg.data.data[i] = 0.0;
639+
}
625640

626641
power_board_temperature_msg.data = 0.0;
627642

628643
power_teensy_temperature_msg.data = 0.0;
629644

645+
//allocates thrusters to 1500 in case of reset and allocates -2.0 to sensing to go under the -1.0 of unintiailized from drivers
646+
647+
for (int i = 0; i < 8; i++) {
648+
propulsion_microseconds_msg.data.data[i] = 1500;
649+
}
650+
for (int i = 0; i < 2; i++) {
651+
power_batteries_voltage_msg.data.data[i] = -2.0;
652+
}
653+
for (int i = 0; i < 8; i++) {
654+
power_thrusters_current_msg.data.data[i] = -2.0;
655+
}
656+
power_board_temperature_msg.data = -2.0;
657+
power_teensy_temperature_msg.data = -2.0;
658+
630659
state = WAITING_AGENT;
631660
}
632661

0 commit comments

Comments
 (0)