-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisteners.cpp
67 lines (57 loc) · 2.57 KB
/
listeners.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
#include "listeners.hpp"
#ifdef DEBUG
#define log(x) std::cout << x << std::endl;
#else
#define log(x)
#endif
// listen to carla/<actor_id>/throttle
void listener::l_throttle(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
float x = sample.get_payload().deserialize<float>();
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.throttle = x;
vehicle->ApplyControl(control);
}
void listener::l_steer(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
float x = sample.get_payload().deserialize<float>();
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.steer = x;
vehicle->ApplyControl(control);
}
// at carla/<actor_id>/brake
void listener::l_brake(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
float x = sample.get_payload().deserialize<float>();
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.brake = x;
vehicle->ApplyControl(control);
}
void listener::l_gear(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
int x = sample.get_payload().deserialize<int>();
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.brake = x;
vehicle->ApplyControl(control);
}
void listener::l_handbrake(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
bool x = sample.get_payload().deserialize<int>() == 1;
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.hand_brake = x;
vehicle->ApplyControl(control);
}
void listener::l_reverse(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
bool x = sample.get_payload().deserialize<int>() == 1;
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.reverse = x;
vehicle->ApplyControl(control);
}
void listener::l_manual_gear(const zenoh::Sample &sample, boost::shared_ptr<cc::Vehicle> vehicle){
bool x = sample.get_payload().deserialize<int>() == 1;
std::cout << "Received " << x << " at " << sample.get_keyexpr().as_string_view() << std::endl;
cc::Vehicle::Control control;
control.manual_gear_shift = x;
vehicle->ApplyControl(control);
}