forked from ApolloAuto/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cyber: add writer nodes for common_component_example and README.md
- Loading branch information
Showing
5 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
47 changes: 47 additions & 0 deletions
47
cyber/examples/common_component_example/channel_prediction_writer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
cyber/examples/common_component_example/channel_test_writer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters