TechTheTime-HighLevel 0.0.1
The high level robot's code using ros2-foxy for the robotics competition(Erobot-2022)
controllerSetup.hpp
Go to the documentation of this file.
1#ifndef __CONTROLLERSETUP_HPP_
2#define __CONTROLLERSETUP_HPP_
3
5#include <array>
6#include <functional>
7#include <unistd.h>
8
9class Binder
10{
11private:
12 std::array<std::function<void(int, bool)>, 11> buttonsCallback;
13 std::array<std::function<void(int, int)>, 8> axisCallback;
14
15public:
17 buttonsCallback.fill([](int, bool) {});
18 axisCallback.fill([](int, int) {});
19 }
20
27 //UTILISER STD::BIND !!!!!
28 void BindButton(int button, std::function<void(int, bool)> func) {
29 buttonsCallback[button] = func;
30 }
31
38 void BindAxis(int axis, std::function<void(int, int)> func) {
39 axisCallback[axis] = func;
40 }
41
42
49 void CallButtonCallback(int button, bool state) {
50 (buttonsCallback.at(button))(button, state);
51 }
52
59 void CallAxisCallback(int axis, int value) {
60 (axisCallback.at(axis))(axis, value);
61 }
62};
63
64// cs = new ControllerSetup<int, float>
66{
67public:
70
74 ControllerSetup() = delete;
75
82
89 ControllerSetup(std::string path, Binder binder);
90
96 void run(bool debug);
97};
98
99#endif
Definition: controllerSetup.hpp:10
void CallAxisCallback(int axis, int value)
Calls the callback assiociated with the axis index.
Definition: controllerSetup.hpp:59
std::array< std::function< void(int, bool)>, 11 > buttonsCallback
Definition: controllerSetup.hpp:12
void BindAxis(int axis, std::function< void(int, int)> func)
Binds the axis index with the callback function.
Definition: controllerSetup.hpp:38
std::array< std::function< void(int, int)>, 8 > axisCallback
Definition: controllerSetup.hpp:13
Binder()
Definition: controllerSetup.hpp:16
void BindButton(int button, std::function< void(int, bool)> func)
Binds the button index with the callback function.
Definition: controllerSetup.hpp:28
void CallButtonCallback(int button, bool state)
Calls the callback assiociated with the button index.
Definition: controllerSetup.hpp:49
Definition: controllerSetup.hpp:66
void run(bool debug)
Runs the controller with the bound callbacks.
Definition: controllerSetup.cpp:25
Joystick joystick
Definition: controllerSetup.hpp:68
ControllerSetup()=delete
Cannot create empty controller.
Binder binder
Definition: controllerSetup.hpp:69
Represents a joystick device.
Definition: joystick.hpp:101