-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from microROS/develop
Develop
- Loading branch information
Showing
53 changed files
with
2,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*) | ||
project(rad0_actuator_c) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclc QUIET) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# Do not compile package if rclcpp is not found | ||
if (NOT rclc_FOUND) | ||
message(WARNING "${PROJECT_NAME} will be ignored due to rclc is not installed") | ||
ament_package() | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} main.c) | ||
ament_target_dependencies(${PROJECT_NAME} rclc std_msgs) | ||
|
||
install(TARGETS | ||
${PROJECT_NAME} | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <rclc/rclc.h> | ||
#include <std_msgs/msg/string.h> | ||
#include <std_msgs/msg/int32.h> | ||
#include <std_msgs/msg/u_int32.h> | ||
|
||
#include <stdio.h> | ||
|
||
#define ASSERT(ptr) if (ptr == NULL) return -1; | ||
|
||
static rclc_publisher_t* engine_pub; | ||
static uint32_t engine_power = 100; | ||
|
||
void engine_on_message(const void* msgin) | ||
{ | ||
|
||
const std_msgs__msg__Int32* msg = (const std_msgs__msg__Int32*)msgin; | ||
|
||
if (msg->data + engine_power > 0) | ||
{ | ||
engine_power += msg->data; | ||
} | ||
else | ||
{ | ||
engine_power = 0; | ||
} | ||
|
||
// Publish new altitude | ||
std_msgs__msg__UInt32 msg_out; | ||
msg_out.data = engine_power; | ||
rclc_publish(engine_pub, (const void*)&msg_out); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
|
||
rclc_node_t* node = NULL; | ||
rclc_subscription_t* engine_sub = NULL; | ||
|
||
|
||
|
||
rclc_init(0, NULL); | ||
node = rclc_create_node("rad0_actuator_c", ""); | ||
ASSERT(node); | ||
engine_sub = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), "std_msgs_msg_Int32", engine_on_message, 1, false); | ||
ASSERT(engine_sub); | ||
engine_pub = rclc_create_publisher(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, UInt32), "std_msgs_msg_UInt32", 1); | ||
ASSERT(engine_pub); | ||
|
||
// Publish new altitude | ||
std_msgs__msg__UInt32 msg_out; | ||
msg_out.data = engine_power; | ||
rclc_publish(engine_pub, (const void*)&msg_out); | ||
|
||
rclc_spin_node(node); | ||
|
||
//if (altitude_sub) rclc_destroy_subscription(altitude_sub); | ||
if (engine_sub) rclc_destroy_subscription(engine_sub); | ||
if (engine_pub) rclc_destroy_publisher(engine_pub); | ||
if (node) rclc_destroy_node(node); | ||
|
||
printf("Actuator node closed.\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>rad0_actuator_c</name> | ||
<version>0.0.1</version> | ||
<description>Real apliacion demostration. Actuator node</description> | ||
<maintainer email="[email protected]">Javier Moreno</maintainer> | ||
<license>Apache License 2.0</license> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<build_depend>rclc</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*) | ||
project(rad0_altitude_sensor_c) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclc QUIET) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# Do not compile package if rclcpp is not found | ||
if (NOT rclc_FOUND) | ||
message(WARNING "${PROJECT_NAME} will be ignored due to rclc is not installed") | ||
ament_package() | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} main.c) | ||
ament_target_dependencies(${PROJECT_NAME} rclc std_msgs) | ||
|
||
target_link_libraries(${PROJECT_NAME} m) | ||
|
||
install(TARGETS | ||
${PROJECT_NAME} | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <rclc/rclc.h> | ||
#include <std_msgs/msg/float64.h> | ||
#include <std_msgs/msg/int32.h> | ||
|
||
#include <stdio.h> | ||
#include <math.h> | ||
#include <time.h> | ||
|
||
#define ASSERT(ptr) if (ptr == NULL) return -1; | ||
|
||
/** | ||
* @brief | ||
* | ||
* @param argc | ||
* @param argv | ||
* @return int | ||
*/ | ||
int main(int argc, char *argv[]) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
rclc_init(0, NULL); | ||
|
||
rclc_node_t* node = NULL; | ||
rclc_publisher_t* publisher = NULL; | ||
|
||
node = rclc_create_node("rad0_altitude_sensor_c", ""); | ||
ASSERT(node); | ||
publisher = rclc_create_publisher(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float64), "std_msgs_msg_Float64", 1); | ||
ASSERT(publisher); | ||
|
||
|
||
double A = 0; | ||
|
||
|
||
while (rclc_ok()) | ||
{ | ||
A += 0.0001; | ||
|
||
// Publish new altitude | ||
std_msgs__msg__Float64 msg; | ||
msg.data = 500 * sin(A) + 950; | ||
rclc_publish(publisher, (const void*)&msg); | ||
|
||
|
||
// Spin node | ||
rclc_spin_node_once(node, 0); | ||
} | ||
|
||
if (publisher) rclc_destroy_publisher(publisher); | ||
if (node) rclc_destroy_node(node); | ||
|
||
printf("altitude sendor closed.\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>rad0_altitude_sensor_c</name> | ||
<version>0.0.1</version> | ||
<description>Real apliacion demostration. Position sensor node</description> | ||
<maintainer email="[email protected]">Javier Moreno</maintainer> | ||
<license>Apache License 2.0</license> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<build_depend>rclc</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*) | ||
project(rad0_display_c) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclc QUIET) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# Do not compile package if rclcpp is not found | ||
if (NOT rclc_FOUND) | ||
message(WARNING "${PROJECT_NAME} will be ignored due to rclc is not installed") | ||
ament_package() | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} main.c) | ||
ament_target_dependencies(${PROJECT_NAME} rclc std_msgs) | ||
|
||
install(TARGETS | ||
${PROJECT_NAME} | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include <rclc/rclc.h> | ||
#include <std_msgs/msg/string.h> | ||
#include <std_msgs/msg/float64.h> | ||
#include <std_msgs/msg/int32.h> | ||
#include <std_msgs/msg/u_int32.h> | ||
|
||
#include <stdio.h> | ||
|
||
#define ASSERT(ptr) if (ptr == NULL) return -1; | ||
|
||
static float altitude; | ||
static uint32_t engine_power; | ||
static unsigned it; | ||
static char Alert[200]; | ||
|
||
/** | ||
* @brief Update screen | ||
* | ||
*/ | ||
void UpdateDisplay() | ||
{ | ||
printf("\r[received messages: %7u] [Altitude: %8.2f] [Engine power: %8u] [Status: %10s]", it++, altitude, engine_power, Alert); | ||
} | ||
|
||
|
||
/** | ||
* @brief new alert callback | ||
* | ||
* @param msgin | ||
*/ | ||
void on_alert_message(const void* msgin) | ||
{ | ||
const std_msgs__msg__String* msg = (const std_msgs__msg__String*)msgin; | ||
strcpy(Alert, msg->data.data); | ||
|
||
UpdateDisplay(); | ||
} | ||
|
||
|
||
/** | ||
* @brief new altitude calback | ||
* | ||
* @param msgin | ||
*/ | ||
void on_altitude_message(const void* msgin) | ||
{ | ||
std_msgs__msg__Float64* msg = (std_msgs__msg__Float64*)msgin; | ||
|
||
altitude = msg->data; | ||
UpdateDisplay(); | ||
} | ||
|
||
/** | ||
* @brief | ||
* | ||
* @param msgin | ||
*/ | ||
void on_power_message(const void* msgin) | ||
{ | ||
std_msgs__msg__UInt32* msg = (std_msgs__msg__UInt32*)msgin; | ||
|
||
engine_power = msg->data; | ||
UpdateDisplay(); | ||
} | ||
|
||
|
||
/** | ||
* @brief Main | ||
* | ||
* @param argc | ||
* @param argv | ||
* @return int | ||
*/ | ||
int main(int argc, char *argv[]) | ||
{ | ||
(void)argc; | ||
(void)argv; | ||
|
||
rclc_node_t* node = NULL; | ||
rclc_subscription_t* alert_subscription = NULL; | ||
rclc_subscription_t* altitude_subscription = NULL; | ||
rclc_subscription_t* power_subscription = NULL; | ||
|
||
|
||
rclc_init(0, NULL); | ||
|
||
node = rclc_create_node("rad0_display_c", ""); | ||
ASSERT(node); | ||
alert_subscription = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, String), "std_msgs_msg_String", on_alert_message, 1, false); | ||
ASSERT(alert_subscription); | ||
altitude_subscription = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float64), "std_msgs_msg_Float64", on_altitude_message, 1, false); | ||
ASSERT(altitude_subscription); | ||
power_subscription = rclc_create_subscription(node, RCLC_GET_MSG_TYPE_SUPPORT(std_msgs, msg, UInt32), "std_msgs_msg_UInt32", on_power_message, 1, false); | ||
ASSERT(power_subscription); | ||
|
||
rclc_spin_node(node); | ||
|
||
if (alert_subscription) rclc_destroy_subscription(alert_subscription); | ||
if (altitude_subscription) rclc_destroy_subscription(altitude_subscription); | ||
if (node) rclc_destroy_node(node); | ||
|
||
printf("Display node closed."); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>rad0_display_c</name> | ||
<version>0.0.1</version> | ||
<description>Real apliacion demostration. Display on screen any message</description> | ||
<maintainer email="[email protected]">Javier Moreno</maintainer> | ||
<license>Apache License 2.0</license> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<build_depend>rclc</build_depend> | ||
<build_depend>std_msgs</build_depend> | ||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*) | ||
project(complex_msg_publisher_c) | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclc QUIET) | ||
find_package(complex_msgs REQUIRED) | ||
|
||
# Do not compile package if rclcpp is not found | ||
if (NOT rclc_FOUND) | ||
message(WARNING "${PROJECT_NAME} will be ignored due to rclc is not installed") | ||
ament_package() | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT_NAME} main.c) | ||
ament_target_dependencies(${PROJECT_NAME} rclc complex_msgs) | ||
|
||
install(TARGETS | ||
${PROJECT_NAME} | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
Oops, something went wrong.