Skip to content

Commit

Permalink
Merge pull request #61 from mROS-base/readme
Browse files Browse the repository at this point in the history
Improve README for custom MsgType
  • Loading branch information
takasehideki committed Feb 23, 2022
2 parents 8adaa6c + faf3b13 commit 14df903
Show file tree
Hide file tree
Showing 17 changed files with 1,220 additions and 169 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ gen/
.settings/
*.launch

# generated header files of custom msgs
mros2_msgs/
# generated file for template functions in mros2-lib
# https://github.com/mROS-base/mros2/blob/9ebc66cbc50f31d332c7d990b7f5bb478d0f35b5/src/mros2.cpp#L281
header_includer/header_includer.hpp

104 changes: 98 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ Please also check [mros2 repository](https://github.com/mROS-base/mros2) for mor
- You can also connect the network with the board through the router when you can set the IP and Netmask as the above.
- The IP address of the board will be assigned to `192.168.11.2`. If you want to change the IP settings, you need to modify [src/config/lwip.c](https://github.com/mROS-base/mros2-asp3-f767zi/blob/main/src/config/lwip.c#L69-L80) and [embeddedRTPS/include/rtps/config.h](https://github.com/mROS-base/embeddedRTPS/blob/mros2/include/rtps/config.h#L37) as you want.

## Usage
## Quickstart

This section explains how to build and execute mROS 2 with TOPPERS/ASP3 kernel, using `echoback_reply` application as an example.

This example only uses a built-in-type (`string` a.k.a `std_msgs::msg::String`), so you can skip the generation of header files for custom msg types. Please see [Generating header files for custom MsgTypes](#generating-header-files-for-custom-msgtypes) for more detail.

### Build for mROS 2 app

First of all, clone this repository. Note that **--recursive** is mandatory.
Expand All @@ -43,7 +45,7 @@ First of all, clone this repository. Note that **--recursive** is mandatory.
$ git clone --recursive https://github.com/mROS-base/mros2-asp3-f767zi
```

Move to workspace and operate `make` with the target app name (please see [workspace/README.md](workspace/README.md) for another examples).
Move to workspace and operate `make` with the target app name (please see [workspace/](workspace/) for another examples).

```
$ cd mros2-asp3-f767zi
Expand Down Expand Up @@ -103,12 +105,12 @@ mROS 2 initialization is completed
ready to pub/sub message
[MROS2LIB] Initilizing Domain complete
```

2. Launch ROS 2 nodes on the host on another terminal.
```
$ cd <your_ros2_ws>
$ source install/local_setup.bash
$ ros2 launch mros2_echoback_string launch_pubsub.py
$ ros2 launch mros2_echoback_string pubsub.launch.py
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [pub_node-1]: process started with pid [21232]
[INFO] [sub_node-2]: process started with pid [21233]
Expand Down Expand Up @@ -146,7 +148,96 @@ We need to start up the mROS 2 node at first, and then operate ROS 2 nodes on th

## Example applications

Please see [workspace](workspace/) for example applications.
Please see [workspace/](workspace/) for example applications.

## Generating header files for custom MsgTypes

You can use almost any [built-in-types in ROS 2](https://docs.ros.org/en/rolling/Concepts/About-ROS-Interfaces.html#field-types) on the embedded device.

In additon, you can define a customized message type (e.g., `Twist.msg`) in the same way as in ROS 2, and use its header file for your application. This section describes how to generate header files for your own MsgTypes (`geometry_msgs::msg::Twist` as an example).

### Prepare .msg files

`.msg` files are simple text files that describe the fields of a ROS message (see [About ROS 2 interface](https://docs.ros.org/en/rolling/Concepts/About-ROS-Interfaces.html)). In mros2, they are used to generate header files for messages in embedded applications.

Prepare `Twist.msg` file and make sure it is in `workspace/custom_msgs/geometry_msgs/msg/`.

```
$ cat workspace/custom_msgs/geometry_msgs/msg/Twist.msg
geometry_msgs/msg/Vector3 linear
geometry_msgs/msg/Vector3 angular
```

In this example, `Twist` has a nested structure with `Vector3` as a child element. So you also need to prepare its file.

```
$ cat workspace/custom_msgs/geometry_msgs/msg/Vector3.msg
float64 x
float64 y
float64 z
```

### Prepare msg_settings.json files

Next, create or edit `msg_settings.json` file under `workspace/custom_msgs/geometry_msgs/` directory. In general, you need to set all paths to `pubsubMsgs`'s value about each .msg files which you want to use. Note that you do not need to add additional paths in this example since `Vector3` will be located in the same hierarchy as `Twist`.

```
$ cat workspace/custom_msgs/geometry_msgs/msg_settings.json
{
"pubsubMsgs": [
"geometry_msgs/msg/Twist.msg"
]
}
```

### Generate header files

To generate header files for `Twist` and `Vector3`, do `make gen-msg msg=geometry_msgs` in `workspace/`.

```
$ cd workspace
$ make gen-msg msg=geometry_msgs
msg file for geometry_msgs generated in custom_msgs/geometry_msgs
```

Make sure header files for custom MsgType are generated in `../mros2_msgs/`

```
$ ls -R ../mros2_msgs/
../mros2_msgs/:
geometry_msgs
../mros2_msgs/geometry_msgs:
msg
../mros2_msgs/geometry_msgs/msg:
twist.hpp vector3.hpp
```

You can now use them in your applicaton like this.

```
#include "mros2.hpp"
#include "geometry_msgs/msg/vector3.hpp"
#include "geometry_msgs/msg/twist.hpp"
int main(int argc, char * argv[])
{
<snip.>
pub = node.create_publisher<geometry_msgs::msg::Twist>("cmd_vel", 10);
<snip.>
```

## Configure the network

There are two files for network configulation.

- [src/startup/include/lwipots.h](https://github.com/mROS-base/mros2-asp3-f767zi/blob/main/src/startup/include/lwipopts.h) for lwIP
- [src/config/rtps/config.h](https://github.com/mROS-base/mros2-asp3-f767zi/blob/main/src/config/rtps/config.h) for embeddedRTPS

Currently, we are unable to communicate large size of messages probably due to these configurations. We should seek the appropreate configurations or how to fit them to the demand of applications.

Please let us know about this if you have any opinions or awesome knowledges! #60

## Tips 1: Execute host nodes with Docker environment

Expand Down Expand Up @@ -192,7 +283,8 @@ Building, flashing and debugging the application can be done with simple operati

## Submodules and Licenses

The source code of this repository itself is published under [Apache License 2.0](https://github.com/mROS-base/mros2/blob/main/LICENSE).
The source code of this repository itself is published under [Apache License 2.0](https://github.com/mROS-base/mros2/blob/main/LICENSE).

Please note that this repository contains the following stacks as the submodules, and also check their Licenses.

- [mros2](https://github.com/mROS-base/mros2): the pub/sub APIs compatible with ROS 2 Rclcpp
Expand Down
Empty file added header_includer/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions header_includer/header_includer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../workspace/sub_pose/templates.hpp"
176 changes: 176 additions & 0 deletions mros2_msgs/geometry_msgs/msg/point.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#ifndef _GEOMETRY_MSGS_MSG_POINT_H
#define _GEOMETRY_MSGS_MSG_POINT_H

#include <iostream>
#include <string>

using namespace std;

namespace geometry_msgs
{
namespace msg
{
class Point
{
public:
uint32_t cntPub = 0;
uint32_t cntSub = 0;


double x
;

double y
;

double z;


uint32_t copyToBuf(uint8_t *addrPtr)
{
uint32_t tmpPub = 0;
uint32_t arraySize;
uint32_t stringSize;



if (cntPub%8 > 0){
for(int i=0; i<(8-(cntPub%8)) ; i++){
*addrPtr = 0;
addrPtr += 1;
}
cntPub += 8-(cntPub%8);
}

memcpy(addrPtr,&x
,8);
addrPtr += 8;
cntPub += 8;





if (cntPub%8 > 0){
for(int i=0; i<(8-(cntPub%8)) ; i++){
*addrPtr = 0;
addrPtr += 1;
}
cntPub += 8-(cntPub%8);
}

memcpy(addrPtr,&y
,8);
addrPtr += 8;
cntPub += 8;





if (cntPub%8 > 0){
for(int i=0; i<(8-(cntPub%8)) ; i++){
*addrPtr = 0;
addrPtr += 1;
}
cntPub += 8-(cntPub%8);
}

memcpy(addrPtr,&z,8);
addrPtr += 8;
cntPub += 8;




return cntPub;
}

uint32_t copyFromBuf(const uint8_t *addrPtr) {
uint32_t tmpSub = 0;
uint32_t arraySize;
uint32_t stringSize;




if (cntSub%8 > 0){
for(int i=0; i<(8-(cntSub%8)) ; i++){
addrPtr += 1;
}
cntSub += 8-(cntSub%8);
}

memcpy(&x
,addrPtr,8);
addrPtr += 8;
cntSub += 8;




if (cntSub%8 > 0){
for(int i=0; i<(8-(cntSub%8)) ; i++){
addrPtr += 1;
}
cntSub += 8-(cntSub%8);
}

memcpy(&y
,addrPtr,8);
addrPtr += 8;
cntSub += 8;




if (cntSub%8 > 0){
for(int i=0; i<(8-(cntSub%8)) ; i++){
addrPtr += 1;
}
cntSub += 8-(cntSub%8);
}

memcpy(&z,addrPtr,8);
addrPtr += 8;
cntSub += 8;



return cntSub;
}

void memAlign(uint8_t *addrPtr){
if (cntPub%4 > 0){
addrPtr += cntPub;
for(int i=0; i<(4-(cntPub%4)) ; i++){
*addrPtr = 0;
addrPtr += 1;
}
cntPub += 4-(cntPub%4);
}
return;
}

uint32_t getTotalSize(){
return cntPub ;
}

private:
std::string type_name = "geometry_msgs::msg::dds_::Point";
};
};
}

namespace message_traits
{
template<>
struct TypeName<geometry_msgs::msg::Point*> {
static const char* value()
{
return "geometry_msgs::msg::dds_::Point_";
}
};
}

#endif
Loading

0 comments on commit 14df903

Please sign in to comment.