Skip to content

Commit c39d7f4

Browse files
author
Javier Moreno
committed
Refs #3364. Build ok. Not tested.
1 parent 5def0c7 commit c39d7f4

8 files changed

Lines changed: 35 additions & 34 deletions

File tree

‎actuator/COLCON_IGNORE‎

Whitespace-only changes.

‎actuator/main.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#include <rclc/rclc.h>
2-
#include <std_msgs/msg/String.h>
3-
#include <std_msgs/msg/Float64.h>
2+
#include <std_msgs/msg/string.h>
3+
#include <std_msgs/msg/float64.h>
44

55
#include <stdio.h>
66

7+
rclc_publisher_t* publisher;
8+
9+
710
void on_message(const void* msgin)
811
{
912
const std_msgs__msg__Float64* msg = (const std_msgs__msg__Float64*)msgin;
1013

11-
12-
printf("I heard: [%i]\n", msg->data);
13-
14-
1514
// Publish warning if value is less than 1000
1615
if (msg->data <= 1000)
1716
{
1817
std_msgs__msg__String Warning;
19-
Warning.data = "Warning";
20-
18+
Warning.data.data = "Warning";
19+
Warning.data.size = strlen(Warning.data.data);
20+
Warning.data.capacity = strlen(Warning.data.data);
21+
2122
rclc_publish(publisher, (const void*)&Warning);
2223
}
2324

@@ -30,7 +31,7 @@ int main(int argc, char* argv[])
3031
rclc_init(0, NULL);
3132
rclc_node_t* node = rclc_create_node("actuator", "");
3233
rclc_subscription_t* sub = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float64), "position_sensor", on_message, 1, false);
33-
rclc_publisher_t* publisher = rclc_create_publisher(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String), "Warning", 1);
34+
publisher = rclc_create_publisher(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String), "Warning", 1);
3435

3536
rclc_spin_node(node);
3637

‎display/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(display)
44

55
find_package(ament_cmake REQUIRED)
66
find_package(rclc REQUIRED)
7-
find_package(display REQUIRED)
7+
find_package(std_msgs REQUIRED)
88

99
add_executable(display main.c)
1010
ament_target_dependencies(display rclc std_msgs)

‎display/COLCON_IGNORE‎

Whitespace-only changes.

‎display/main.c‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
#include <rclc/rclc.h>
2-
#include <std_msgs/msg/float64.h>
2+
#include <std_msgs/msg/string.h>
33

44
#include <stdio.h>
5-
#include <math.h>
6-
#include <time.h>
5+
6+
static unsigned WaringCount = 0;
7+
8+
void on_message(const void* msgin)
9+
{
10+
const std_msgs__msg__String* msg = (const std_msgs__msg__String*)msgin;
11+
12+
13+
printf("[%i] %s\n", WaringCount++, msg->data.data);
14+
}
15+
716

817
int main(int argc, char *argv[])
918
{
1019
(void)argc;
1120
(void)argv;
21+
1222
rclc_init(0, NULL);
13-
rclc_node_t* node = rclc_create_node("display", "");
14-
rclc_publisher_t* publisher = rclc_create_publisher(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float64), "position_sensor", 1);
15-
16-
std_msgs__msg__Float64 msg;
17-
msg.data = 0;
18-
double Count = 0;
19-
srand((unsigned) time(&t));
20-
21-
while (rclc_ok())
22-
{
23-
// Emulate senoidal change position 2000 to 0
24-
Count += 0.1;
25-
msg.data = 1000* sin(Count) + 1000;
26-
27-
rclc_publish(publisher, (const void*)&msg);
28-
rclc_spin_node_once(node, (rand() % 900 + 100));
29-
}
30-
31-
if (publisher) rclc_destroy_publisher(publisher);
32-
if (node) rclc_destroy_node(node);
3323

34-
return 0;
24+
rclc_node_t* node = rclc_create_node("display", "");
25+
rclc_subscription_t* sub = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String), "Warning", on_message, 1, false);
26+
27+
rclc_spin_node(node);
28+
29+
if (sub) rclc_destroy_subscription(sub);
30+
if (node) rclc_destroy_node(node);
31+
3532
}

‎position_sensor/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ find_package(std_msgs REQUIRED)
99
add_executable(position_sensor main.c)
1010
ament_target_dependencies(position_sensor rclc std_msgs)
1111

12+
target_link_libraries(position_sensor m)
13+
1214
install(TARGETS
1315
position_sensor
1416
DESTINATION lib/${PROJECT_NAME}

‎position_sensor/COLCON_IGNORE‎

Whitespace-only changes.

‎position_sensor/main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main(int argc, char *argv[])
1616
std_msgs__msg__Float64 msg;
1717
msg.data = 0;
1818
double Count = 0;
19+
time_t t;
1920
srand((unsigned) time(&t));
2021

2122
while (rclc_ok())

0 commit comments

Comments
 (0)