2
2
3
3
rcl_subscription_t propulsion_microseconds_subscriber;
4
4
std_msgs__msg__Int16MultiArray propulsion_microseconds_msg;
5
+
6
+ rcl_publisher_t power_board_temperature_publisher;
7
+ std_msgs__msg__Float32 power_board_temperature_msg;
8
+
5
9
rclc_executor_t executor;
6
10
rclc_support_t support;
7
11
rcl_allocator_t allocator;
8
12
rcl_node_t node;
9
- rcl_timer_t timer;
10
13
11
14
void micro_ros_init () {
12
15
set_microros_transports ();
@@ -30,6 +33,15 @@ void micro_ros_init() {
30
33
propulsion_microseconds_msg.data .size = 8 ;
31
34
propulsion_microseconds_msg.data .capacity = 8 ;
32
35
36
+ // create publisher
37
+ RCCHECK (rclc_publisher_init_default (
38
+ &power_board_temperature_publisher,
39
+ &node,
40
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Float32),
41
+ " /power/board/temperature" ));
42
+
43
+ power_board_temperature_msg.data = 0.0 ;
44
+
33
45
// Create executor
34
46
RCCHECK (rclc_executor_init (&executor, &support.context , 1 , &allocator));
35
47
RCCHECK (rclc_executor_add_subscription (&executor, &propulsion_microseconds_subscriber, &propulsion_microseconds_msg, &propulsion_microseconds_subscription_callback, ON_NEW_DATA));
@@ -45,6 +57,8 @@ void error_loop() {
45
57
free (propulsion_microseconds_msg.data .data );
46
58
}
47
59
60
+ power_board_temperature_msg.data = 0.0 ;
61
+
48
62
int error = 0 ;
49
63
50
64
while (error <= 20 ) {
@@ -57,6 +71,11 @@ void error_loop() {
57
71
digitalWrite (LED_PIN, HIGH);
58
72
}
59
73
74
+ void power_board_temperature_publish (float power_board_temperature) {
75
+ power_board_temperature_msg.data = power_board_temperature;
76
+ RCSOFTCHECK (rcl_publish (&power_board_temperature_publisher, &power_board_temperature_msg, NULL ));
77
+ }
78
+
60
79
void propulsion_microseconds_subscription_callback (const void * msgin) {
61
80
const std_msgs__msg__Int16MultiArray * propulsion_microseconds_msg = (const std_msgs__msg__Int16MultiArray *)msgin;
62
81
0 commit comments