Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:2bcae3be966f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Mar 19 09:12:22 2022 +0900 @@ -0,0 +1,50 @@ +/* mros2 example + * Copyright (c) 2021 smorita_emb + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbed.h" +#include "mros2.h" +#include "geometry_msgs/msg/pose.hpp" +#include "EthernetInterface.h" + +#define IP_ADDRESS ("192.168.11.2") /* IP address */ +#define SUBNET_MASK ("255.255.255.0") /* Subnet mask */ +#define DEFAULT_GATEWAY ("192.168.11.1") /* Default gateway */ + + +void userCallback(geometry_msgs::msg::Pose *msg) +{ + MROS2_INFO("subscribed Pose msg!!"); +} + +int main() { + EthernetInterface network; + network.set_dhcp(false); + network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY); + nsapi_size_or_error_t result = network.connect(); + + printf("mbed mros2 start!\r\n"); + printf("app name: sub_pose\r\n"); + mros2::init(0, NULL); + MROS2_DEBUG("mROS 2 initialization is completed\r\n"); + + mros2::Node node = mros2::Node::create_node("sub_pose"); + mros2::Subscriber sub = node.create_subscription<geometry_msgs::msg::Pose>("cmd_vel", 10, userCallback); + + MROS2_INFO("ready to pub/sub message"); + + mros2::spin(); + return 0; +} \ No newline at end of file