Apollo 10.0
自动驾驶开放平台
talker.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
17#include "cyber/examples/proto/examples.pb.h"
18
19#include "cyber/cyber.h"
20#include "cyber/time/rate.h"
21#include "cyber/time/time.h"
22
26
27int main(int argc, char *argv[]) {
28 // init cyber framework
29 apollo::cyber::Init(argv[0]);
30 // create talker node
31 auto talker_node = apollo::cyber::CreateNode("talker");
32 // create talker
33 auto talker = talker_node->CreateWriter<Chatter>("channel/chatter");
34 Rate rate(1.0);
35 uint64_t seq = 0;
36 while (apollo::cyber::OK()) {
37 auto msg = std::make_shared<Chatter>();
38 msg->set_timestamp(Time::Now().ToNanosecond());
39 msg->set_lidar_timestamp(Time::Now().ToNanosecond());
40 msg->set_seq(seq);
41 msg->set_content("Hello, apollo!");
42 talker->Write(msg);
43 AINFO << "talker sent a message! No. " << seq;
44 seq++;
45 rate.Sleep();
46 }
47 return 0;
48}
Cyber has builtin time type Time.
Definition time.h:31
static Time Now()
get the current time.
Definition time.cc:57
#define AINFO
Definition log.h:42
bool Init(const char *binary_name, const std::string &dag_info)
Definition init.cc:98
bool OK()
Definition state.h:44
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
Definition cyber.cc:33
int main(int argc, char *argv[])
Definition talker.cc:27