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.
main.cpp@0:2bcae3be966f, 2022-03-19 (annotated)
- Committer:
- smoritaemb
- Date:
- Sat Mar 19 09:12:22 2022 +0900
- Revision:
- 0:2bcae3be966f
Imported app.cpp from the mros2 example.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
smoritaemb | 0:2bcae3be966f | 1 | /* mros2 example |
smoritaemb | 0:2bcae3be966f | 2 | * Copyright (c) 2021 smorita_emb |
smoritaemb | 0:2bcae3be966f | 3 | * |
smoritaemb | 0:2bcae3be966f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
smoritaemb | 0:2bcae3be966f | 5 | * you may not use this file except in compliance with the License. |
smoritaemb | 0:2bcae3be966f | 6 | * You may obtain a copy of the License at |
smoritaemb | 0:2bcae3be966f | 7 | * |
smoritaemb | 0:2bcae3be966f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
smoritaemb | 0:2bcae3be966f | 9 | * |
smoritaemb | 0:2bcae3be966f | 10 | * Unless required by applicable law or agreed to in writing, software |
smoritaemb | 0:2bcae3be966f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
smoritaemb | 0:2bcae3be966f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
smoritaemb | 0:2bcae3be966f | 13 | * See the License for the specific language governing permissions and |
smoritaemb | 0:2bcae3be966f | 14 | * limitations under the License. |
smoritaemb | 0:2bcae3be966f | 15 | */ |
smoritaemb | 0:2bcae3be966f | 16 | |
smoritaemb | 0:2bcae3be966f | 17 | #include "mbed.h" |
smoritaemb | 0:2bcae3be966f | 18 | #include "mros2.h" |
smoritaemb | 0:2bcae3be966f | 19 | #include "geometry_msgs/msg/pose.hpp" |
smoritaemb | 0:2bcae3be966f | 20 | #include "EthernetInterface.h" |
smoritaemb | 0:2bcae3be966f | 21 | |
smoritaemb | 0:2bcae3be966f | 22 | #define IP_ADDRESS ("192.168.11.2") /* IP address */ |
smoritaemb | 0:2bcae3be966f | 23 | #define SUBNET_MASK ("255.255.255.0") /* Subnet mask */ |
smoritaemb | 0:2bcae3be966f | 24 | #define DEFAULT_GATEWAY ("192.168.11.1") /* Default gateway */ |
smoritaemb | 0:2bcae3be966f | 25 | |
smoritaemb | 0:2bcae3be966f | 26 | |
smoritaemb | 0:2bcae3be966f | 27 | void userCallback(geometry_msgs::msg::Pose *msg) |
smoritaemb | 0:2bcae3be966f | 28 | { |
smoritaemb | 0:2bcae3be966f | 29 | MROS2_INFO("subscribed Pose msg!!"); |
smoritaemb | 0:2bcae3be966f | 30 | } |
smoritaemb | 0:2bcae3be966f | 31 | |
smoritaemb | 0:2bcae3be966f | 32 | int main() { |
smoritaemb | 0:2bcae3be966f | 33 | EthernetInterface network; |
smoritaemb | 0:2bcae3be966f | 34 | network.set_dhcp(false); |
smoritaemb | 0:2bcae3be966f | 35 | network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY); |
smoritaemb | 0:2bcae3be966f | 36 | nsapi_size_or_error_t result = network.connect(); |
smoritaemb | 0:2bcae3be966f | 37 | |
smoritaemb | 0:2bcae3be966f | 38 | printf("mbed mros2 start!\r\n"); |
smoritaemb | 0:2bcae3be966f | 39 | printf("app name: sub_pose\r\n"); |
smoritaemb | 0:2bcae3be966f | 40 | mros2::init(0, NULL); |
smoritaemb | 0:2bcae3be966f | 41 | MROS2_DEBUG("mROS 2 initialization is completed\r\n"); |
smoritaemb | 0:2bcae3be966f | 42 | |
smoritaemb | 0:2bcae3be966f | 43 | mros2::Node node = mros2::Node::create_node("sub_pose"); |
smoritaemb | 0:2bcae3be966f | 44 | mros2::Subscriber sub = node.create_subscription<geometry_msgs::msg::Pose>("cmd_vel", 10, userCallback); |
smoritaemb | 0:2bcae3be966f | 45 | |
smoritaemb | 0:2bcae3be966f | 46 | MROS2_INFO("ready to pub/sub message"); |
smoritaemb | 0:2bcae3be966f | 47 | |
smoritaemb | 0:2bcae3be966f | 48 | mros2::spin(); |
smoritaemb | 0:2bcae3be966f | 49 | return 0; |
smoritaemb | 0:2bcae3be966f | 50 | } |