Skip to content

Commit 5def0c7

Browse files
author
Javier Moreno
committed
Refs #3364. Not working yet
1 parent 77bb081 commit 5def0c7

12 files changed

Lines changed: 211 additions & 0 deletions

File tree

‎actuator/CMakeLists.txt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*)
3+
project(actuator)
4+
5+
find_package(ament_cmake REQUIRED)
6+
find_package(rclc REQUIRED)
7+
find_package(std_msgs REQUIRED)
8+
9+
add_executable(actuator main.c)
10+
ament_target_dependencies(actuator rclc std_msgs)
11+
12+
install(TARGETS
13+
actuator
14+
DESTINATION lib/${PROJECT_NAME}
15+
)
16+
17+
ament_package()

‎actuator/COLCON_IGNORE‎

Whitespace-only changes.

‎actuator/main.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <rclc/rclc.h>
2+
#include <std_msgs/msg/String.h>
3+
#include <std_msgs/msg/Float64.h>
4+
5+
#include <stdio.h>
6+
7+
void on_message(const void* msgin)
8+
{
9+
const std_msgs__msg__Float64* msg = (const std_msgs__msg__Float64*)msgin;
10+
11+
12+
printf("I heard: [%i]\n", msg->data);
13+
14+
15+
// Publish warning if value is less than 1000
16+
if (msg->data <= 1000)
17+
{
18+
std_msgs__msg__String Warning;
19+
Warning.data = "Warning";
20+
21+
rclc_publish(publisher, (const void*)&Warning);
22+
}
23+
24+
}
25+
26+
int main(int argc, char* argv[])
27+
{
28+
(void)argc;
29+
(void)argv;
30+
rclc_init(0, NULL);
31+
rclc_node_t* node = rclc_create_node("actuator", "");
32+
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+
35+
rclc_spin_node(node);
36+
37+
if (sub) rclc_destroy_subscription(sub);
38+
if (publisher) rclc_destroy_publisher(publisher);
39+
if (node) rclc_destroy_node(node);
40+
41+
return 0;
42+
}

‎actuator/package.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>actuator</name>
5+
<version>0.0.1</version>
6+
<description>Demo. Actuator node</description>
7+
<maintainer email="javiermoreno@eprosima.com">Javier Moreno</maintainer>
8+
<license>Apache License 2.0</license>
9+
<buildtool_depend>ament_cmake</buildtool_depend>
10+
<build_depend>rclc</build_depend>
11+
<build_depend>std_msgs</build_depend>
12+
<export>
13+
<build_type>ament_cmake</build_type>
14+
</export>
15+
</package>
16+

‎display/CMakeLists.txt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*)
3+
project(display)
4+
5+
find_package(ament_cmake REQUIRED)
6+
find_package(rclc REQUIRED)
7+
find_package(display REQUIRED)
8+
9+
add_executable(display main.c)
10+
ament_target_dependencies(display rclc std_msgs)
11+
12+
install(TARGETS
13+
display
14+
DESTINATION lib/${PROJECT_NAME}
15+
)
16+
17+
ament_package()

‎display/COLCON_IGNORE‎

Whitespace-only changes.

‎display/main.c‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <rclc/rclc.h>
2+
#include <std_msgs/msg/float64.h>
3+
4+
#include <stdio.h>
5+
#include <math.h>
6+
#include <time.h>
7+
8+
int main(int argc, char *argv[])
9+
{
10+
(void)argc;
11+
(void)argv;
12+
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);
33+
34+
return 0;
35+
}

‎display/package.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>display</name>
5+
<version>0.0.1</version>
6+
<description>Demo. Display on screen any message</description>
7+
<maintainer email="javiermoreno@eprosima.com">Javier Moreno</maintainer>
8+
<license>Apache License 2.0</license>
9+
<buildtool_depend>ament_cmake</buildtool_depend>
10+
<build_depend>rclc</build_depend>
11+
<build_depend>std_msgs</build_depend>
12+
<export>
13+
<build_type>ament_cmake</build_type>
14+
</export>
15+
</package>
16+

‎position_sensor/CMakeLists.txt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*)
3+
project(position_sensor)
4+
5+
find_package(ament_cmake REQUIRED)
6+
find_package(rclc REQUIRED)
7+
find_package(std_msgs REQUIRED)
8+
9+
add_executable(position_sensor main.c)
10+
ament_target_dependencies(position_sensor rclc std_msgs)
11+
12+
install(TARGETS
13+
position_sensor
14+
DESTINATION lib/${PROJECT_NAME}
15+
)
16+
17+
ament_package()

‎position_sensor/COLCON_IGNORE‎

Whitespace-only changes.

0 commit comments

Comments
 (0)