Skip to content

Commit b410ad7

Browse files
committed
follow bumps of mros2 v0.5.1-3, and revert filename as the default in idf.py create-project
1 parent 6dea160 commit b410ad7

File tree

25 files changed

+195
-145
lines changed

25 files changed

+195
-145
lines changed

workspace/echoback_string/main/echoback_string.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,41 @@
2121

2222
void userCallback(std_msgs::msg::String *msg)
2323
{
24-
printf("subscribed msg: '%s'\r\n", msg->data.c_str());
24+
MROS2_INFO("subscribed msg: '%s'", msg->data.c_str());
2525
}
2626

2727
extern "C" void app_main(void)
2828
{
29-
printf("mbed mros2 start!\r\n");
30-
printf("app name: echoback_string\r\n");
31-
3229
/* connect to the network */
3330
if (mros2_platform_network_connect())
3431
{
35-
MROS2_INFO("successfully connect and setup network\r\n");
32+
MROS2_INFO("successfully connect and setup network\r\n---");
3633
}
3734
else
3835
{
39-
MROS2_ERROR("failed to connect and setup network! aborting,,,\r\n");
36+
MROS2_ERROR("failed to connect and setup network! aborting,,,");
4037
return;
4138
}
4239

40+
MROS2_INFO("%s start!", MROS2_PLATFORM_NAME);
41+
MROS2_INFO("app name: echoback_string");
42+
4343
mros2::init(0, NULL);
44-
MROS2_DEBUG("mROS 2 initialization is completed\r\n");
44+
MROS2_DEBUG("mROS 2 initialization is completed");
4545

4646
mros2::Node node = mros2::Node::create_node("mros2_node");
4747
mros2::Publisher pub = node.create_publisher<std_msgs::msg::String>("to_linux", 10);
4848
mros2::Subscriber sub = node.create_subscription<std_msgs::msg::String>("to_stm", 10, userCallback);
4949

5050
osDelay(100);
51-
MROS2_INFO("ready to pub/sub message\r\n");
51+
MROS2_INFO("ready to pub/sub message\r\n---");
5252

5353
auto count = 0;
5454
while (1)
5555
{
5656
auto msg = std_msgs::msg::String();
5757
msg.data = "Hello from " + std::string(MROS2_PLATFORM_NAME) + " onto " + quote(TARGET_NAME) + ": " + std::to_string(count++);
58-
printf("publishing msg: '%s'\r\n", msg.data.c_str());
58+
MROS2_INFO("publishing msg: '%s'", msg.data.c_str());
5959
pub.publish(msg);
6060
osDelay(1000);
6161
}

workspace/echoreply_string/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# CMakeLists in this exact order for cmake to work correctly
33
cmake_minimum_required(VERSION 3.16)
44

5-
set(EXTRA_COMPONENT_DIRS ../../ ../../platform)
5+
set(EXTRA_COMPONENT_DIRS ../..)
66
add_compile_options(-w)
77

88
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
idf_component_register(SRCS "app.cpp"
1+
idf_component_register(SRCS "echoreply_string.cpp"
22
INCLUDE_DIRS "."
3-
PRIV_REQUIRES "mros2-esp32" "wifi")
3+
PRIV_REQUIRES "mros2-esp32")

workspace/echoreply_string/main/app.cpp renamed to workspace/echoreply_string/main/echoreply_string.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mros2 example
2-
* Copyright (c) 2021 smorita_emb
2+
* Copyright (c) 2023 mROS-base
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,36 +15,44 @@
1515
*/
1616

1717
#include "mros2.h"
18+
#include "mros2-platform.h"
1819
#include "std_msgs/msg/string.hpp"
1920

20-
#include "cmsis_os.h"
21-
#include "wifi.h"
22-
2321
mros2::Subscriber sub;
2422
mros2::Publisher pub;
2523

24+
2625
void userCallback(std_msgs::msg::String *msg)
2726
{
28-
printf("subscribed msg: '%s'\r\n", msg->data.c_str());
29-
printf("publishing msg: '%s'\r\n", msg->data.c_str());
27+
MROS2_INFO("subscribed msg: '%s'", msg->data.c_str());
28+
MROS2_INFO("publishing msg: '%s'", msg->data.c_str());
3029
pub.publish(*msg);
3130
}
3231

3332
extern "C" void app_main(void)
3433
{
35-
init_wifi();
36-
osKernelStart();
34+
/* connect to the network */
35+
if (mros2_platform_network_connect())
36+
{
37+
MROS2_INFO("successfully connect and setup network\r\n---");
38+
}
39+
else
40+
{
41+
MROS2_ERROR("failed to connect and setup network! aborting,,,");
42+
return;
43+
}
44+
45+
MROS2_INFO("mbed mros2 start!");
46+
MROS2_INFO("app name: echoreply_string");
3747

38-
printf("mbed mros2 start!\r\n");
39-
printf("app name: echoreply_string\r\n");
4048
mros2::init(0, NULL);
41-
MROS2_DEBUG("mROS 2 initialization is completed\r\n");
49+
MROS2_DEBUG("mROS 2 initialization is completed");
4250

4351
mros2::Node node = mros2::Node::create_node("mros2_node");
4452
pub = node.create_publisher<std_msgs::msg::String>("to_linux", 10);
4553
sub = node.create_subscription<std_msgs::msg::String>("to_stm", 10, userCallback);
4654
osDelay(100);
47-
MROS2_INFO("ready to pub/sub message\r\n");
55+
MROS2_INFO("ready to pub/sub message\r\n---");
4856

4957
mros2::spin();
5058
return;

workspace/m5stack_sample/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# CMakeLists in this exact order for cmake to work correctly
33
cmake_minimum_required(VERSION 3.16)
44

5-
set(EXTRA_COMPONENT_DIRS ../../ ../../platform)
5+
set(EXTRA_COMPONENT_DIRS ../..)
66
add_compile_options(-w)
77

88
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
idf_component_register(SRCS "app.cpp"
1+
idf_component_register(SRCS "m5stack_sample.cpp"
22
INCLUDE_DIRS "."
3-
PRIV_REQUIRES "mros2-esp32" "wifi" "M5Unified")
3+
PRIV_REQUIRES "mros2-esp32" "M5Unified")

workspace/m5stack_sample/main/app.cpp renamed to workspace/m5stack_sample/main/m5stack_sample.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mros2 example
2-
* Copyright (c) 2022 mROS-base
2+
* Copyright (c) 2023 mROS-base
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,50 +15,59 @@
1515
*/
1616

1717
#include "mros2.h"
18+
#include "mros2-platform.h"
1819
#include "std_msgs/msg/string.hpp"
1920

20-
#include "cmsis_os.h"
21-
#include "wifi.h"
22-
2321
#include "M5Unified.h"
24-
/* convert TARGET_NAME to put into message */
25-
#define quote(x) std::string(q(x))
26-
#define q(x) #x
22+
2723

2824
void userCallback(std_msgs::msg::String *msg)
2925
{
30-
printf("subscribed msg: '%s'\r\n", msg->data.c_str());
26+
MROS2_INFO("subscribed msg: '%s'", msg->data.c_str());
3127
M5.Lcd.printf("subscribed msg: '%s'\r\n", msg->data.c_str());
3228
}
3329

3430
extern "C" void app_main(void)
3531
{
36-
init_wifi();
37-
osKernelStart();
32+
/* connect to the network */
33+
if (mros2_platform_network_connect())
34+
{
35+
MROS2_INFO("successfully connect and setup network\r\n---");
36+
}
37+
else
38+
{
39+
MROS2_ERROR("failed to connect and setup network! aborting,,,");
40+
return;
41+
}
42+
43+
MROS2_INFO("%s start!", MROS2_PLATFORM_NAME);
44+
MROS2_INFO("app name: echoback_string");
3845

3946
auto cfg = M5.config();
4047
M5.begin(cfg);
4148
M5.Lcd.setTextSize(2);
42-
M5.Lcd.println("mbed mros2 start!\r\n");
49+
M5.Lcd.println("");
50+
M5.Lcd.printf("%s start!\r\n", MROS2_PLATFORM_NAME);
4351
M5.Lcd.printf("app name: m5stack_sample\r\n");
4452

4553
mros2::init(0, NULL);
46-
MROS2_DEBUG("mROS 2 initialization is completed\r\n");
54+
MROS2_DEBUG("mROS 2 initialization is completed");
4755

4856
mros2::Node node = mros2::Node::create_node("mros2_node");
4957
mros2::Publisher pub = node.create_publisher<std_msgs::msg::String>("to_linux", 10);
5058
mros2::Subscriber sub = node.create_subscription<std_msgs::msg::String>("to_stm", 10, userCallback);
5159

5260
osDelay(100);
53-
MROS2_INFO("ready to pub/sub message\r\n");
61+
MROS2_INFO("ready to pub/sub message\r\n---");
5462

5563
auto count = 0;
5664
while (1)
5765
{
5866
auto msg = std_msgs::msg::String();
5967
msg.data = "Hello from mros2-mbed onto " + quote(TARGET_NAME) + ": " + std::to_string(count++);
60-
printf("publishing msg: '%s'\r\n", msg.data.c_str());
68+
MROS2_INFO("publishing msg: '%s'", msg.data.c_str());
6169
pub.publish(msg);
70+
M5.Lcd.printf("publishing msg: '%s'\r\n", msg.data.c_str());
6271
osDelay(1000);
6372
}
6473

workspace/pub_float32/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# CMakeLists in this exact order for cmake to work correctly
33
cmake_minimum_required(VERSION 3.16)
44

5-
set(EXTRA_COMPONENT_DIRS ../../ ../../platform)
5+
set(EXTRA_COMPONENT_DIRS ../..)
66
add_compile_options(-w)
77

88
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
idf_component_register(SRCS "app.cpp"
1+
idf_component_register(SRCS "pub_float32.cpp"
22
INCLUDE_DIRS "."
3-
PRIV_REQUIRES "mros2-esp32" "wifi")
3+
PRIV_REQUIRES "mros2-esp32")

workspace/pub_float32/main/app.cpp renamed to workspace/pub_float32/main/pub_float32.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mros2 example
2-
* Copyright (c) 2021 smorita_emb
2+
* Copyright (c) 2023 mROS-base
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,25 +15,33 @@
1515
*/
1616

1717
#include "mros2.h"
18+
#include "mros2-platform.h"
1819
#include "std_msgs/msg/float32.hpp"
1920

20-
#include "cmsis_os.h"
21-
#include "wifi.h"
2221

2322
extern "C" void app_main(void)
2423
{
25-
init_wifi();
26-
osKernelStart();
24+
/* connect to the network */
25+
if (mros2_platform_network_connect())
26+
{
27+
MROS2_INFO("successfully connect and setup network\r\n---");
28+
}
29+
else
30+
{
31+
MROS2_ERROR("failed to connect and setup network! aborting,,,");
32+
return;
33+
}
34+
35+
MROS2_INFO("mbed mros2 start!");
36+
MROS2_INFO("app name: pub_float32");
2737

28-
printf("mbed mros2 start!\r\n");
29-
printf("app name: pub_float32\r\n");
3038
mros2::init(0, NULL);
31-
MROS2_DEBUG("mROS 2 initialization is completed\r\n");
39+
MROS2_DEBUG("mROS 2 initialization is completed");
3240

3341
mros2::Node node = mros2::Node::create_node("mros2_node");
3442
mros2::Publisher pub = node.create_publisher<std_msgs::msg::Float32>("to_linux", 10);
3543
osDelay(100);
36-
MROS2_INFO("ready to pub/sub message\r\n");
44+
MROS2_INFO("ready to pub/sub message\r\n---");
3745

3846
std_msgs::msg::Float32 msg;
3947
auto publish_count = -0.5;
@@ -44,17 +52,13 @@ extern "C" void app_main(void)
4452
pub.publish(msg);
4553

4654
if (0.0 >= msg.data)
47-
printf("msg <= 0.0\r\n");
55+
MROS2_INFO("msg <= 0.0");
4856
else if (0.0 < msg.data && msg.data < 0.5)
49-
printf("0.0 < msg < 0.5\r\n");
57+
MROS2_INFO("0.0 < msg < 0.5");
5058
else if (0.5 < msg.data && msg.data < 1.0)
51-
printf("0.5 < msg < 1.0\r\n");
59+
MROS2_INFO("0.5 < msg < 1.0");
5260
else
53-
printf("msg >= 1.0\r\n");
54-
/*
55-
* you need to add `"target.printf_lib": "std"` into mbed_app.json
56-
printf("publishing msg: '%f'\r\n", msg.data);
57-
*/
61+
MROS2_INFO("msg >= 1.0");
5862

5963
publish_count = publish_count + 0.1;
6064
osDelay(1000);

0 commit comments

Comments
 (0)