@@ -420,6 +420,8 @@ void power_loop() {
420
420
421
421
#include < std_msgs/msg/int32.h>
422
422
#include < std_msgs/msg/int16_multi_array.h>
423
+ #include < std_msgs/msg/float32.h>
424
+ #include < std_msgs/msg/float32_multi_array.h>
423
425
424
426
#if !defined(MICRO_ROS_TRANSPORT_ARDUINO_SERIAL)
425
427
#error This example is only avaliable for Arduino framework with serial transport.
@@ -429,14 +431,20 @@ void power_loop() {
429
431
430
432
bool micro_ros_init_successful;
431
433
432
- rcl_subscription_t array_subscriber ;
433
- std_msgs__msg__Int16MultiArray array_msg_subscription ;
434
+ rcl_subscription_t propulsion_microseconds_subscriber ;
435
+ std_msgs__msg__Int16MultiArray propulsion_microseconds_msg ;
434
436
435
- rcl_publisher_t publisher ;
436
- std_msgs__msg__Int32 msg ;
437
+ rcl_publisher_t power_batteries_voltage_publisher ;
438
+ std_msgs__msg__Float32MultiArray power_batteries_voltage_msg ;
437
439
438
- rcl_publisher_t array_publisher;
439
- std_msgs__msg__Int16MultiArray array_msg_publishing;
440
+ rcl_publisher_t power_thrusters_current_publisher;
441
+ std_msgs__msg__Float32MultiArray power_thrusters_current_msg;
442
+
443
+ rcl_publisher_t power_board_temperature_publisher;
444
+ std_msgs__msg__Float32 power_board_temperature_msg;
445
+
446
+ rcl_publisher_t power_teensy_temperature_publisher;
447
+ std_msgs__msg__Float32 power_teensy_temperature_msg;
440
448
441
449
rclc_executor_t executor;
442
450
rclc_support_t support;
@@ -471,13 +479,7 @@ enum states {
471
479
AGENT_DISCONNECTED
472
480
} state;
473
481
474
- void subscription_callback (const void * msgin)
475
- {
476
- const std_msgs__msg__Int32 * msg = (const std_msgs__msg__Int32 *)msgin;
477
- digitalWrite (LED_PIN, (msg->data == 0 ) ? LOW : HIGH);
478
- }
479
-
480
- void array_subscription_callback (const void * msgin)
482
+ void propulsion_microseconds_callback (const void * msgin)
481
483
{
482
484
const std_msgs__msg__Int16MultiArray * msg = (const std_msgs__msg__Int16MultiArray *)msgin;
483
485
@@ -496,18 +498,12 @@ void array_subscription_callback(const void * msgin)
496
498
void timer_callback (rcl_timer_t * timer, int64_t last_call_time) {
497
499
RCLC_UNUSED (last_call_time);
498
500
if (timer != NULL ) {
499
- RCSOFTCHECK (rcl_publish (&publisher, &msg, NULL ));
500
- RCSOFTCHECK (rcl_publish (&array_publisher, &array_msg_publishing, NULL ));
501
- msg.data ++;
501
+ RCSOFTCHECK (rcl_publish (&power_batteries_voltage_publisher, &power_batteries_voltage_publisher, NULL ));
502
+ RCSOFTCHECK (rcl_publish (&power_thrusters_current_publisher, &power_thrusters_current_msg, NULL ));
503
+ RCSOFTCHECK (rcl_publish (&power_board_temperature_publisher, &power_board_temperature_msg, NULL ));
504
+ RCSOFTCHECK (rcl_publish (&power_teensy_temperature_publisher, &power_teensy_temperature_msg, NULL ));
502
505
503
- array_msg_publishing.data .data [0 ]++;
504
- array_msg_publishing.data .data [1 ]++;
505
- array_msg_publishing.data .data [2 ]++;
506
- array_msg_publishing.data .data [3 ]++;
507
- array_msg_publishing.data .data [4 ]++;
508
- array_msg_publishing.data .data [5 ]++;
509
- array_msg_publishing.data .data [6 ]++;
510
- array_msg_publishing.data .data [7 ]++;
506
+ // can add logic to messages here
511
507
}
512
508
}
513
509
@@ -519,29 +515,41 @@ bool create_entities()
519
515
RCCHECK (rclc_support_init (&support, 0 , NULL , &allocator));
520
516
521
517
// create node
522
- RCCHECK (rclc_node_init_default (&node, " int32_publisher_rclc" , " " , &support));
518
+ RCCHECK (rclc_node_init_default (&node, " power_node" , " " , &support));
519
+
520
+ RCCHECK (rclc_subscription_init_default (
521
+ &propulsion_microseconds_subscriber,
522
+ &node,
523
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int16MultiArray),
524
+ " /propulsion/microseconds" ));
523
525
524
526
// / create publisher
525
527
RCCHECK (rclc_publisher_init_default (
526
- &publisher ,
528
+ &power_batteries_voltage_publisher ,
527
529
&node,
528
- ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int32 ),
529
- " micro_ros_platformio_node_publisher " ));
530
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Float32MultiArray ),
531
+ " /power/batteries/voltage " ));
530
532
531
533
RCCHECK (rclc_publisher_init_default (
532
- &array_publisher ,
534
+ &power_thrusters_current_publisher ,
533
535
&node,
534
- ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int16MultiArray),
535
- " array_publisher" ));
536
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Float32MultiArray),
537
+ " /power/thrusters/current" ));
538
+
539
+ RCCHECK (rclc_publisher_init_default (
540
+ &power_board_temperature_publisher,
541
+ &node,
542
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Float32),
543
+ " /power/board/temperature" ));
536
544
537
- RCCHECK (rclc_subscription_init_default (
538
- &array_subscriber ,
545
+ RCCHECK (rclc_publisher_init_default (
546
+ &power_teensy_temperature_publisher ,
539
547
&node,
540
- ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Int16MultiArray ),
541
- " array_subscriber " ));
548
+ ROSIDL_GET_MSG_TYPE_SUPPORT (std_msgs, msg, Float32 ),
549
+ " /power/teensy/temperature " ));
542
550
543
551
// create timer,
544
- const unsigned int timer_timeout = 1000 ;
552
+ const unsigned int timer_timeout = 100 ;
545
553
RCCHECK (rclc_timer_init_default (
546
554
&timer,
547
555
&support,
@@ -550,9 +558,9 @@ bool create_entities()
550
558
551
559
// create executor
552
560
executor = rclc_executor_get_zero_initialized_executor ();
553
- RCCHECK (rclc_executor_init (&executor, &support.context , 10 , &allocator)); // number arbitrarily set, idk what is the correct on yet, trial and error later on
561
+ RCCHECK (rclc_executor_init (&executor, &support.context , 100 , &allocator)); // number arbitrarily set, idk what is the correct on yet, trial and error later on
554
562
RCCHECK (rclc_executor_add_timer (&executor, &timer));
555
- RCCHECK (rclc_executor_add_subscription (&executor, &array_subscriber , &array_msg_subscription , &array_subscription_callback , ON_NEW_DATA));
563
+ RCCHECK (rclc_executor_add_subscription (&executor, &propulsion_microseconds_subscriber , &propulsion_microseconds_msg , &propulsion_microseconds_callback , ON_NEW_DATA));
556
564
557
565
558
566
return true ;
@@ -574,9 +582,11 @@ void destroy_entities()
574
582
rmw_context_t * rmw_context = rcl_context_get_rmw_context (&support.context );
575
583
(void ) rmw_uros_set_context_entity_destroy_session_timeout (rmw_context, 0 );
576
584
577
- rcl_publisher_fini (&publisher, &node);
578
- rcl_publisher_fini (&array_publisher, &node);
579
- rcl_subscription_fini (&array_subscriber, &node);
585
+ rcl_publisher_fini (&power_batteries_voltage_publisher, &node);
586
+ rcl_publisher_fini (&power_thrusters_current_publisher, &node);
587
+ rcl_publisher_fini (&power_board_temperature_publisher, &node);
588
+ rcl_publisher_fini (&power_teensy_temperature_publisher, &node);
589
+ rcl_subscription_fini (&propulsion_microseconds_subscriber, &node);
580
590
rcl_timer_fini (&timer);
581
591
rclc_executor_fini (&executor);
582
592
rcl_node_fini (&node);
@@ -605,25 +615,19 @@ void power_setup() {
605
615
set_microros_serial_transports (Serial);
606
616
delay (2000 );
607
617
608
- array_msg_publishing .data .size = 8 ;
609
- array_msg_publishing .data .capacity = 8 ;
610
- array_msg_publishing .data .data = (int16_t *)malloc (array_msg_publishing .data .capacity * sizeof (int16_t ));
618
+ propulsion_microseconds_msg .data .size = 8 ;
619
+ propulsion_microseconds_msg .data .capacity = 8 ;
620
+ propulsion_microseconds_msg .data .data = (int16_t *)malloc (propulsion_microseconds_msg .data .capacity * sizeof (int16_t ));
611
621
612
- array_msg_subscription .data .size = 8 ;
613
- array_msg_subscription .data .capacity = 8 ;
614
- array_msg_subscription .data .data = (int16_t *)malloc (array_msg_subscription .data .capacity * sizeof (int16_t ));
622
+ power_batteries_voltage_msg .data .size = 2 ;
623
+ power_batteries_voltage_msg .data .capacity = 2 ;
624
+ power_batteries_voltage_msg .data .data = (float *)malloc (power_batteries_voltage_msg .data .capacity * sizeof (float ));
615
625
616
- state = WAITING_AGENT ;
626
+ power_board_temperature_msg. data = 0.0 ;
617
627
618
- msg.data = 0 ;
619
- array_msg_publishing.data .data [0 ] = 0 ;
620
- array_msg_publishing.data .data [1 ] = 1 ;
621
- array_msg_publishing.data .data [2 ] = 2 ;
622
- array_msg_publishing.data .data [3 ] = 3 ;
623
- array_msg_publishing.data .data [4 ] = 4 ;
624
- array_msg_publishing.data .data [5 ] = 5 ;
625
- array_msg_publishing.data .data [6 ] = 6 ;
626
- array_msg_publishing.data .data [7 ] = 7 ;
628
+ power_teensy_temperature_msg.data = 0.0 ;
629
+
630
+ state = WAITING_AGENT;
627
631
}
628
632
629
633
void power_loop () {
0 commit comments