Vicente Monge
8 years ago
committed by
Beat Küng
3 changed files with 1 additions and 587 deletions
@ -1,115 +0,0 @@
@@ -1,115 +0,0 @@
|
||||
# Hello world |
||||
|
||||
As a basic example we go to explain how implement a simple use case what sends information of some sensors (*sensor_combined* uORB topic) in the direction PX4-Fast RTPS and receives information as a text message (*log_message* uORB topic) sent in the other direction. |
||||
|
||||
## Creating the code |
||||
|
||||
``` sh |
||||
$ cd /path/to/PX4/Firmware |
||||
$ python Tools/generate_microRTPS_bridge.py --send msg/sensor_combined.msg --receive msg/sensor_combined.msg msg/log_message.msg -u src/examples/micrortps_client |
||||
``` |
||||
**NOTE**: It may be needed specify other different arguments, as the path to the Fast RTPS *bin* installation folder if it was installed in other path different to default one (*-f /path/to/fastrtps/installation/bin*). For more information, click this [link](README.md#generate-and-installing-the-client-and-the-agent). |
||||
|
||||
That generates and installs the PX4 side of the code (the client) in *src/examples/micrortps_client* and the Fast RPS side (the agent) in *src/modules/micrortps_bridge/micrortps_agent*. |
||||
|
||||
To see the message received in the client one time each second (**src/examples/micrortps_client/microRTPS_client.cpp**), we change the default value of the sleep to 1000 and we will add this *printf* to the code under the *orb_publish* line for *log_message* topic (line 274): |
||||
|
||||
```cpp |
||||
... |
||||
#define SLEEP_MS 1000 |
||||
... |
||||
... |
||||
... |
||||
case 36: |
||||
{ |
||||
deserialize_log_message(&log_message_data, data_buffer, µCDRReader); |
||||
if (!log_message_pub) |
||||
log_message_pub = orb_advertise(ORB_ID(log_message), &log_message_data); |
||||
else |
||||
orb_publish(ORB_ID(log_message), log_message_pub, &log_message_data); |
||||
printf("%s\n", log_message_data.text); |
||||
++received; |
||||
} |
||||
... |
||||
``` |
||||
To enable the compilation of the example client we need to modify the *micrortps_client* line in the cmake of our platform (*cmake/configs*) in that way: |
||||
|
||||
``` cmake |
||||
set(config_module_list |
||||
... |
||||
#src/modules/micrortps_bridge/micrortps_client |
||||
src/examples/micrortps_client |
||||
... |
||||
) |
||||
``` |
||||
|
||||
Also we need to a add basic CMakeLists.txt like that: |
||||
|
||||
``` cmake |
||||
px4_add_module( |
||||
MODULE examples__micrortps_client |
||||
MAIN micrortps_client |
||||
STACK_MAIN 4096 |
||||
SRCS |
||||
microRTPS_transport.cxx |
||||
microRTPS_client.cpp |
||||
DEPENDS |
||||
platforms__common |
||||
) |
||||
``` |
||||
|
||||
Now, we change the agent in order to send a log message each time we receive a **Fast RTPS message** with the info of the uORB topic *sensor_combined* (in the Fast RTPS world this topic will be called *sensor_combined_PubSubTopic*). |
||||
|
||||
- In the **src/modules/micrortps_bridge/micrortps_agent/RtpsTopic.cxx** file we will change the *RtpsTopics::getMsg* function to return a *log_message* for each *sensor_combined* with the text "*The temperature is XX.XXXXXXX celsius degrees*": |
||||
|
||||
```cpp |
||||
bool RtpsTopics::getMsg(const char topic_ID, eprosima::fastcdr::Cdr &scdr) |
||||
{ |
||||
bool ret = false; |
||||
switch (topic_ID) |
||||
{ |
||||
case 58: // sensor_combined |
||||
if (_sensor_combined_sub.hasMsg()) |
||||
{ |
||||
sensor_combined_ msg = _sensor_combined_sub.getMsg(); |
||||
log_message_ log_msg = {}; |
||||
std::string message = "The temperature is " + std::to_string(msg.baro_temp_celcius()) + " celsius degrees"; |
||||
std::memcpy(log_msg.text().data(), message.c_str(), message.length()); |
||||
log_msg.serialize(scdr); |
||||
ret = true; |
||||
} |
||||
break; |
||||
default: |
||||
printf("Unexpected topic ID to getMsg\n"); |
||||
break; |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
``` |
||||
|
||||
- In the **src/micrortps_bridge/micrortps_agent/microRTPS_agent.cxx** we will change the topic ID of the received message to the topic ID of the *log_message* (**36**) that is really the topic we are handling: |
||||
|
||||
```cpp |
||||
... |
||||
if (topics.getMsg(topic_ID, scdr)) |
||||
{ |
||||
topic_ID = 36; |
||||
length = scdr.getSerializedDataLength(); |
||||
if (0 < (length = transport_node->write(topic_ID, scdr.getBufferPointer(), length))) |
||||
{ |
||||
total_sent += length; |
||||
++sent; |
||||
} |
||||
} |
||||
... |
||||
``` |
||||
## Result |
||||
|
||||
After compiling and launching both the [client](README.md#px4-firmware-the-micro-rtps-client) and the [agent](README.md#fast-rtps-the-micro-rtps-agent) we obtain this kind of messages in the client shell window (showing the message created in the agent with info from temperature sensor in the PX4 side): |
||||
|
||||
```sh |
||||
... |
||||
The temperature is: 47.779999 celsius |
||||
... |
||||
``` |
@ -1,87 +0,0 @@
@@ -1,87 +0,0 @@
|
||||
# Micro RTPS Throughput Test |
||||
|
||||
This a simple test to measure the throughput of the bridge. Sending an receiving messages of the 256 bytes at the same time as fast as we can. |
||||
|
||||
We will create a new message for this test called **throughput_256.msg**, the content look like this: |
||||
|
||||
``` text |
||||
uint8[256] data |
||||
``` |
||||
We will create it next to the other *.msg* files in the folder *msg/*: |
||||
|
||||
``` sh |
||||
$ cd /path/to/PX4/Firmware/msg |
||||
$ echo uint8[256] data > throughput_256.msg |
||||
``` |
||||
Now, we register the new message adding it to the list of messages in the *msg/CMakeLists.txt* file: |
||||
|
||||
``` cmake |
||||
... |
||||
wind_estimate.msg |
||||
throughput_256.msg |
||||
) |
||||
... |
||||
``` |
||||
And giving it a topic id, adding a line in the *Tools/message_id.py* script: |
||||
|
||||
``` python |
||||
... |
||||
'wind_estimate': 94, |
||||
'throughput_256': 95, |
||||
} |
||||
... |
||||
``` |
||||
|
||||
## Creating the code |
||||
|
||||
First at all, we need to disable the automatic generation in the PX4 compiling process setting the variable `GENERATE_RTPS_BRIDGE` to *off* inside the *.cmake* file for the target platform (*cmake/configs/*): |
||||
|
||||
```sh |
||||
set(GENERATE_RTPS_BRIDGE off) |
||||
``` |
||||
|
||||
And then generate the code: |
||||
|
||||
``` sh |
||||
$ cd /path/to/PX4/Firmware |
||||
$ python Tools/generate_microRTPS_bridge.py --send msg/throughput_256.msg --receive msg/throughput_256.msg |
||||
``` |
||||
|
||||
That generates and installs the PX4 side of the code (the client) in *src/modules/micrortps_bridge/micrortps_client* and the Fast RPS side (the agent) in *src/modules/micrortps_bridge/micrortps_agent*. |
||||
|
||||
Now, we have to modify the client to send a *throughput_256* message each time since nobody publish under this topic. In the file **src/modules/micrortps_bridge/micrortps_client/microRTPS_client.cpp** inside the *send* function the while loop should look like this: |
||||
|
||||
``` cpp |
||||
... |
||||
while (!_should_exit_task) |
||||
{ |
||||
//bool updated; |
||||
//orb_check(fds[0], &updated); |
||||
//if (updated) |
||||
{ |
||||
// obtained data for the file descriptor |
||||
struct throughput_256_s data = {}; |
||||
// copy raw data into local buffer |
||||
//orb_copy(ORB_ID(throughput_256), fds[0], &data); |
||||
data.data[0] = loop%256; |
||||
serialize_throughput_256(&data, data_buffer, &length, µCDRWriter); |
||||
if (0 < (read = transport_node->write((char)95, data_buffer, length))) |
||||
{ |
||||
total_sent += read; |
||||
++sent; |
||||
} |
||||
} |
||||
|
||||
usleep(_options.sleep_ms*1000); |
||||
++loop; |
||||
} |
||||
... |
||||
``` |
||||
## Result |
||||
|
||||
After compiling and launching both the [client](README.md#px4-firmware-side-the-micro-rtps-client) and the [agent](README.md#fast-rtps-side-the-micro-rtps-agent) we obtain a measure of throughput for our particular conditions. For a Pixracer and a ordinary PC running Ubuntu 16.04 in the client shell window we obtain: |
||||
|
||||
```sh |
||||
SENT: 13255 messages in 13255 LOOPS, 3512575 bytes in 30.994 seconds - 113.33KB/s |
||||
RECEIVED: 13251 messages in 10000 LOOPS, 3511515 bytes in 30.994 seconds - 113.30KB/s |
||||
``` |
Loading…
Reference in new issue