Skip to content

Commit 6457f25

Browse files
committed
added temeprature sensor publisher - to test
1 parent a49b313 commit 6457f25

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

pio_workspace/lib/power_custom/power_micro_ros.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
rcl_subscription_t propulsion_microseconds_subscriber;
44
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+
59
rclc_executor_t executor;
610
rclc_support_t support;
711
rcl_allocator_t allocator;
812
rcl_node_t node;
9-
rcl_timer_t timer;
1013

1114
void micro_ros_init() {
1215
set_microros_transports();
@@ -30,6 +33,15 @@ void micro_ros_init() {
3033
propulsion_microseconds_msg.data.size = 8;
3134
propulsion_microseconds_msg.data.capacity = 8;
3235

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+
3345
// Create executor
3446
RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
3547
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() {
4557
free(propulsion_microseconds_msg.data.data);
4658
}
4759

60+
power_board_temperature_msg.data = 0.0;
61+
4862
int error = 0;
4963

5064
while(error <= 20) {
@@ -57,6 +71,11 @@ void error_loop() {
5771
digitalWrite(LED_PIN, HIGH);
5872
}
5973

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+
6079
void propulsion_microseconds_subscription_callback(const void * msgin) {
6180
const std_msgs__msg__Int16MultiArray * propulsion_microseconds_msg = (const std_msgs__msg__Int16MultiArray *)msgin;
6281

pio_workspace/lib/power_custom/power_micro_ros.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
#include <rclc/executor.h>
99

1010
#include <std_msgs/msg/int16_multi_array.h>
11+
#include <std_msgs/msg/float32.h>
1112

1213
#define LED_PIN 13
1314

1415
extern rcl_subscription_t propulsion_microseconds_subscriber;
1516
extern std_msgs__msg__Int16MultiArray propulsion_microseconds_msg;
17+
18+
extern rcl_publisher_t power_board_temperature_publisher;
19+
extern std_msgs__msg__Float32 power_board_temperature_msg;
20+
1621
extern rclc_executor_t executor;
1722
extern rclc_support_t support;
1823
extern rcl_allocator_t allocator;
1924
extern rcl_node_t node;
20-
extern rcl_timer_t timer;
2125

2226
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
2327
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
@@ -28,4 +32,6 @@ void micro_ros_init();
2832
void spin_micro_ros();
2933
void error_loop();
3034

35+
void power_board_temperature_publish(float power_board_temperature);
36+
3137
void propulsion_microseconds_subscription_callback(const void * msgin);

pio_workspace/src/power_main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "power_micro_ros.h"
77

88
#define LED_PIN 13
9+
#define TEMP_SENSE 23
10+
11+
TMP36 temperature_sensor(TEMP_SENSE, 3.3);
912

1013
void power_setup() {
1114
pinMode(LED_PIN, OUTPUT);
@@ -14,13 +17,17 @@ void power_setup() {
1417
initThrusters();
1518

1619
micro_ros_init();
20+
21+
temperature_sensor.begin();
1722

1823
delay(2000);
1924
}
2025

2126
void power_loop() {
2227
updateThrusters(microseconds);
2328

29+
power_board_temperature_publish(temperature_sensor.readTemperature());
30+
2431
spin_micro_ros();
2532

2633
delay(10);

0 commit comments

Comments
 (0)