Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
RemoteControl.cpp
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <stdio.h>
6 
7 #include <utils/logger.hpp>
8 #include <unistd.h>
9 
10 using namespace galaxis::ros;
11 using namespace galaxis::utils;
12 
14  rclcpp::Node("SimulationRemoteControl") {
15  rclcpp::QoS qos_params = get_qos_profile(QOS_BEST_EFFORT);
16  m_publisherSPtr = this->create_publisher<SimulationVehicleControlType>("galaxis/simulation/remotecontrol", qos_params);
17  log("Vehicle Control Message Publisher created.");
18 
19  loop();
20 }
21 
23  system("stty cooked");
24 }
25 
27  log("Start RemoteControl Loop");
28  log("Press 'w a d 1 2 3 4 e' for drive and ESC/q for quit");
29 
30  // get raw input from terminal
31  system("stty raw");
32 
33  log("Waiting for input...");
34 
35  int index = 0;
36  while(true) {
37  char c;
38  c = getchar();
39 
40  // DO NOT REMOVE THIS LINE!
41  if(c == 'q' || c == 27) {
42  m_speed = 0.f;
44  break;
45  }
46 
47  switch(c) {
48  case 'w':
49  m_yaw = 0.f;
50  break;
51  case 'a':
52  m_yaw += 0.15;
53  break;
54  case 'd':
55  m_yaw += -0.15;
56  break;
57  case '1':
58  m_speed = 0.f;
59  break;
60  case '2':
61  m_speed = 0.3f;
62  break;
63  case '3':
64  m_speed = 1.f;
65  break;
66  case '4':
67  m_speed = 2.f;
68  break;
69  case 'r':
70  m_reset = true;
71  break;
72  case 'e':
73  m_remoteEnabled = m_remoteEnabled ? false : true;
74  m_speed = 0.f;
75  break;
76  default:
77  log(" No Command. [", c, "] ");
78  break;
79  }
80 
81  log_nonewline("\r[", ++index, "] Update VehicleControl Inputs. Speed: ", m_speed, " [m/s] Turning Angle: ", m_yaw, " ");
83 
84  usleep(100000);
85  }
86  system("stty cooked");
87 
88  log("\nRemoteControl exited.");
89  exit(0);
90 }
91 
93  auto message = std::make_unique<SimulationVehicleControlType>();
94 
95  message->car_speed = m_speed;
96  message->turnangle_front = m_yaw;
97 
98  message->reset = m_reset;
99  m_reset = false;
100 
101  message->remote_control = m_remoteEnabled ? 1 : 0;
102 
103  m_publisherSPtr->publish(std::move(message));
104 }
node_ros_pubsub_wrapper.hpp
galaxis::ros
Definition: node_ros_pubsub_wrapper.hpp:15
galaxis::utils::log_nonewline
void log_nonewline(const Args &... args)
Definition: logger.hpp:18
RemoteControl::RemoteControl
RemoteControl()
Definition: RemoteControl.cpp:13
RemoteControl.hpp
RemoteControl::loop
void loop()
Definition: RemoteControl.cpp:26
RemoteControl::m_yaw
float m_yaw
Definition: RemoteControl.hpp:16
RemoteControl::m_reset
bool m_reset
Definition: RemoteControl.hpp:17
RemoteControl::~RemoteControl
~RemoteControl()
Definition: RemoteControl.cpp:22
RemoteControl::m_speed
float m_speed
Definition: RemoteControl.hpp:15
logger.hpp
galaxis::utils
Definition: clock.hpp:5
RemoteControl::sendControlInputs
void sendControlInputs()
Definition: RemoteControl.cpp:92
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
RemoteControl::m_publisherSPtr
rclcpp::Publisher< SimulationVehicleControlType >::SharedPtr m_publisherSPtr
Definition: RemoteControl.hpp:21
RemoteControl::m_remoteEnabled
bool m_remoteEnabled
Definition: RemoteControl.hpp:18