-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_data.cpp
85 lines (66 loc) · 2.59 KB
/
control_data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <random>
#include <variant>
#include <thread>
#include <chrono>
#define ZENOHCXX_ZENOHC
#include "zenoh.hxx"
using namespace zenoh;
using namespace std::chrono_literals;
/*
FIXME Extreme memory congestion when simulator is shut down
*/
int main(){
// random number generation setup
std::random_device rd;
std::mt19937 e(rd());
std::uniform_real_distribution<> df(0.0, 1.0);
std::uniform_int_distribution<> di(1, 6);
std::uniform_int_distribution<> db(0, 1);
// test data publish to topics under carla/<actor_id>
// i.e. carla/<actor_id>/throttle
Config config = Config::create_default();
auto session = Session::open(std::move(config));
int actorId;
std::cin >> actorId;
std::string topic_prefix = "carla/" + std::to_string(actorId);
auto p_throttle = session.declare_publisher(topic_prefix + "/throttle");
auto p_steer = session.declare_publisher(topic_prefix + "/steer");
auto p_brake = session.declare_publisher(topic_prefix + "/brake");
auto p_handbrake = session.declare_publisher(topic_prefix + "/handbrake");
auto p_reverse = session.declare_publisher(topic_prefix + "/reverse");
auto p_gear = session.declare_publisher(topic_prefix + "/gear");
auto p_mgs = session.declare_publisher(topic_prefix + "/manual-gear-shift");
for (int i = 0; i < 100000; ++i){
std::this_thread::sleep_for(1s);
p_throttle.put(1.0f);
std::cout << "Instance " << i << ": " << 1 << std::endl;
/*
std::cout << "-------------- Instance " << i << " -----------------" << std::endl;
float throttle = df(e);
p_throttle.put(throttle);
std::cout << "Throttle: " << throttle << std::endl;
float steer = df(e);
p_steer.put(steer);
std::cout << "Steer: " << steer << std::endl;
float brake = df(e);
p_brake.put(brake);
std::cout << "Brake: " << brake << std::endl;
int handbrake = i < 10000 ? 1 : 0;
p_handbrake.put(handbrake);
std::cout << "Handbrake: " << handbrake << std::endl;
int reverse = 0;
p_reverse.put(reverse);
std::cout << "Reverse: " << reverse << std::endl;
int gear = di(e);
p_gear.put(gear);
std::cout << "Gear: " << gear << std::endl;
int mgs = 0;
p_mgs.put(mgs);
std::cout << "Manual gear shift: " << mgs << std::endl;
// std::cout << "Handbrake: " << db(e) << std::endl;
// std::cout << "Reverse: " << db(e) << std::endl;
// std::cout << "Gear: " << di(e) << std::endl;
*/
}
}