Skip to content

Commit b6ece1e

Browse files
authored
Merge 2c79db3 into a6fbd92
2 parents a6fbd92 + 2c79db3 commit b6ece1e

File tree

12 files changed

+389
-55
lines changed

12 files changed

+389
-55
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ configure_file(${CMAKE_SOURCE_DIR}/tutorials.md.in ${CMAKE_BINARY_DIR}/tutorials
173173
gz_create_docs(
174174
API_MAINPAGE_MD "${CMAKE_BINARY_DIR}/api.md"
175175
TUTORIALS_MAINPAGE_MD "${CMAKE_BINARY_DIR}/tutorials.md"
176+
IMAGE_PATH_DIRS "${CMAKE_SOURCE_DIR}/tutorials/files"
176177
TAGFILES
177178
"${GZ-MATH_DOXYGEN_TAGFILE} = ${GZ-MATH_API_URL}"
178179
)

examples/generating_custom_msgs/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
1515

1616
# Example of custom messages that depend on gz.msgs
1717
set(MSGS_PROTOS
18-
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/vector3d.proto)
18+
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/foo.proto
19+
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/bar.proto
20+
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/baz.proto
21+
)
1922

2023
gz_msgs_generate_messages(
2124
# The cmake target to be generated for libraries/executables to link
@@ -32,7 +35,6 @@ gz_msgs_generate_messages(
3235

3336
add_executable(${PROJECT_NAME} main.cc)
3437

35-
# Automatically uses whole-archive linking to get all the messages available
3638
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}-msgs)
3739

3840
install(TARGETS ${PROJECT_NAME}

examples/generating_custom_msgs/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,3 @@ gz_msgs_generate_messages(
5757
# List of message targets this library imports from
5858
DEPENDENCIES gz_msgs_gen)
5959
```
60-
61-
Be sure to link all dependent message targets:
62-
63-
```
64-
# Automatically uses whole-archive linking to get all the messages available
65-
target_link_messages(TARGET ${PROJECT_NAME} PUBLIC MSG_TARGETS custom_msgs_gen gz_msgs_gen)
66-
```
Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,68 @@
1-
#include <gz/msgs/vector3d.pb.h>
2-
#include <gz/custom_msgs/vector3d.pb.h>
1+
#include <gz/custom_msgs/foo.pb.h>
2+
#include <gz/custom_msgs/bar.pb.h>
3+
#include <gz/custom_msgs/baz.pb.h>
34

45
#include <google/protobuf/text_format.h>
56

67
// A simple example that demonstrates the use of the message factory
78
//
8-
// Usage:
9-
// Print text description of original and custom Vector3d msgs.
109
// ./generating_custom_messages
1110
int main(int argc, char** argv)
1211
{
1312
(void) argc;
1413
(void) argv;
15-
// Print the text description of the original message
16-
gz::msgs::Vector3d original;
14+
15+
gz::custom_msgs::BazStamped msg;
16+
17+
// msg has header and baz field
18+
auto *header = msg.mutable_header();
19+
auto *baz = msg.mutable_baz();
20+
1721
{
18-
auto descriptor = original.GetDescriptor();
19-
auto fileDescriptor = descriptor->file();
20-
std::cout << "Name: " << descriptor->full_name() << std::endl;
21-
std::cout << "File: " << fileDescriptor->name() << std::endl << std::endl;
22-
std::cout << descriptor->DebugString() << std::endl;
22+
// Populate the header with something
23+
header->mutable_stamp()->set_sec(100);
24+
header->mutable_stamp()->set_nsec(100);
25+
}
26+
27+
{
28+
// Add a frame_id to the header
29+
auto map_entry = header->add_data();
30+
map_entry->set_key("frame_id");
31+
map_entry->add_value("gz_custom_msgs");
2332
}
2433

25-
// Print the text description of the custom message
26-
gz::custom_msgs::Vector3d custom;
2734
{
28-
auto descriptor = custom.GetDescriptor();
35+
// Add an arbitrary array value to the header
36+
auto map_entry = header->add_data();
37+
map_entry->set_key("array");
38+
map_entry->add_value("a");
39+
map_entry->add_value("b");
40+
map_entry->add_value("c");
41+
}
42+
43+
// baz has foo and bar field;
44+
auto *foo = baz->mutable_foo();
45+
auto *bar = baz->mutable_bar();
46+
47+
{
48+
// Set the values of our custom sub-messges
49+
foo->set_value(1.0);
50+
bar->set_value(1.0);
51+
}
52+
53+
{
54+
// Print the text descriptor of a message
55+
auto descriptor = msg.GetDescriptor();
2956
auto fileDescriptor = descriptor->file();
57+
std::cout << "Message definition: " << std::endl;
3058
std::cout << "Name: " << descriptor->full_name() << std::endl;
3159
std::cout << "File: " << fileDescriptor->name() << std::endl << std::endl;
3260
std::cout << descriptor->DebugString() << std::endl;
3361
}
62+
63+
{
64+
// Print the populated values of a message
65+
std::cout << "===============================" << std::endl;
66+
std::cout << "Pouplated Message: \n" << msg.DebugString() << std::endl;
67+
}
3468
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package gz.custom_msgs;
3+
4+
import "gz/msgs/header.proto";
5+
6+
message Bar
7+
{
8+
double value = 1;
9+
}
10+
11+
message BarStamped
12+
{
13+
gz.msgs.Header header = 1;
14+
gz.custom_msgs.Bar bar = 2;
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
syntax = "proto3";
2+
package gz.custom_msgs;
3+
4+
import "gz/msgs/header.proto";
5+
6+
import "gz/custom_msgs/foo.proto";
7+
import "gz/custom_msgs/bar.proto";
8+
9+
message Baz
10+
{
11+
gz.custom_msgs.Foo foo = 1;
12+
gz.custom_msgs.Bar bar = 2;
13+
}
14+
15+
message BazStamped
16+
{
17+
gz.msgs.Header header = 1;
18+
gz.custom_msgs.Baz baz = 2;
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
package gz.custom_msgs;
3+
4+
import "gz/msgs/header.proto";
5+
6+
message Foo
7+
{
8+
double value = 1;
9+
}
10+
11+
message FooStamped
12+
{
13+
gz.msgs.Header header = 1;
14+
gz.custom_msgs.Foo foo = 2;
15+
}

examples/generating_custom_msgs/proto/gz/custom_msgs/vector3d.proto

Lines changed: 0 additions & 32 deletions
This file was deleted.

tutorials.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Gazebo @GZ_DESIGNATION_CAP@ library and how to use the library effectively.
88

99
1. \subpage install "Installation"
1010
2. \subpage cppgetstarted "C++ Get Started"
11+
3. \subpage messagegeneration "Message Generation"
1112

1213
## License
1314

tutorials/files/gz_msgs_factory.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)