Skip to content

Commit

Permalink
Cyber: add writer nodes for common_component_example and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
storypku committed Jul 20, 2020
1 parent 020cdbb commit 21d4a06
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cyber/examples/common_component_example/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@ cc_library(
],
)

cc_binary(
name = "channel_test_writer",
srcs = ["channel_test_writer.cc"],
deps = [
"//cyber",
"//cyber/examples/proto:examples_cc_proto",
],
)

cc_binary(
name = "channel_prediction_writer",
srcs = ["channel_prediction_writer.cc"],
deps = [
"//cyber",
"//cyber/examples/proto:examples_cc_proto",
],
)

cpplint()
55 changes: 55 additions & 0 deletions cyber/examples/common_component_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Common Component Example of the CyberRT framework


## How to Build

```
./apollo.sh build cyber
```

Or if you use Bazel directly,

```
bazel build //cyber/examples/common_component_example/...
```

## How to Run

### Enable logging to stderr

- Change `GLOG_alsologtostderr` from `0` to `1` in `cyber/setup.bash`
- Run `source cyber/setup.bash` in current console.

```
export GLOG_alsologtostderr=1
```

### Start the sample component

```
cyber_launch start cyber/examples/common_component_example/common.launch
```

Or

```
mainbooard -d cyber/examples/common_component_example/common.dag
```

### Start the writer nodes

Open two more terminals, run the following commands respectively.

```
bazel run //cyber/examples/common_component_example:channel_test_writer
```

and ...

```
bazel run //cyber/examples/common_component_example:channel_prediction_writer
```

Now you should see console output of the `CommonComponentSample` example from the first terminal.


Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* 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 "cyber/cyber.h"
#include "cyber/examples/proto/examples.pb.h"
#include "cyber/time/rate.h"
#include "cyber/time/time.h"

using apollo::cyber::Rate;
using apollo::cyber::Time;
using apollo::cyber::examples::proto::Driver;

int main(int argc, char *argv[]) {
// init cyber framework
apollo::cyber::Init(argv[0]);
// create talker node
auto talker_node = apollo::cyber::CreateNode("prediction_writer");
// create talker
auto talker = talker_node->CreateWriter<Driver>("/apollo/prediction");
Rate rate(3.0);

std::string content("apollo_prediction");
while (apollo::cyber::OK()) {
static uint64_t seq = 0;
auto msg = std::make_shared<Driver>();
msg->set_timestamp(Time::Now().ToNanosecond());
msg->set_msg_id(seq++);
msg->set_content(content + std::to_string(seq - 1));
talker->Write(msg);
AINFO << "/apollo/prediction sent message, seq=" << (seq - 1) << ";";
rate.Sleep();
}
return 0;
}
47 changes: 47 additions & 0 deletions cyber/examples/common_component_example/channel_test_writer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* 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 "cyber/cyber.h"
#include "cyber/examples/proto/examples.pb.h"
#include "cyber/time/rate.h"
#include "cyber/time/time.h"

using apollo::cyber::Rate;
using apollo::cyber::Time;
using apollo::cyber::examples::proto::Driver;

int main(int argc, char *argv[]) {
// init cyber framework
apollo::cyber::Init(argv[0]);
// create talker node
auto talker_node = apollo::cyber::CreateNode("channel_test_writer");
// create talker
auto talker = talker_node->CreateWriter<Driver>("/apollo/test");
Rate rate(2.0);

std::string content("apollo_test");
while (apollo::cyber::OK()) {
static uint64_t seq = 0;
auto msg = std::make_shared<Driver>();
msg->set_timestamp(Time::Now().ToNanosecond());
msg->set_msg_id(seq++);
msg->set_content(content + std::to_string(seq - 1));
talker->Write(msg);
AINFO << "/apollo/test sent message, seq=" << (seq - 1) << ";";
rate.Sleep();
}
return 0;
}
7 changes: 6 additions & 1 deletion docker/build/installers/install_qa_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ apt-get -y update && \
valgrind \
libgoogle-perftools4 # gperftools

ln -s /usr/lib/${TARGET_ARCH}-linux-gnu/libprofiler.so.0 /usr/lib/${TARGET_ARCH}-linux-gnu/libprofiler.so
PROFILER_SO="/usr/lib/${TARGET_ARCH}-linux-gnu/libprofiler.so"

if [ ! -e "${PROFILER_SO}" ]; then
# libgoogle-perftools4: /usr/lib/x86_64-linux-gnu/libprofiler.so.0
ln -s "${PROFILER_SO}.0" "${PROFILER_SO}"
fi

## Pylint
pip3_install pycodestyle
Expand Down

0 comments on commit 21d4a06

Please sign in to comment.