Software_Joystick service
As mentioned before in this phase, before making it autonomous I am going to use a joystick to control the cub. This is what I am currently using:
![]() |
| Logitech Extreme 3D PRO |
There are many ways to get the output from these devices. There are lots of libraries and we can even read the data directly from the device which is not flexible. For this purpose I am going to use SFML which is basically a lightweight 2D game engine and I have some experiences using it. The way this library is usually used is through the game loop, the loop that goes on and on through the entire period of the game, each time returning all of the events regarding mouse, keyboard, joystick, etc in the context of the game window. Since we don't need the game window and the game loop we should use the other way. We are going to use it using the update function manually and subsequently checking for the joystick events.
To make the code more open-close I used observer/observable pattern. There is a class called Joystick_mediator. The class has a main_loop function which is basically a while true, with a multi milliseconds sleep that within each iteration saves all joystick events inside a variable. This class subscribes instances of any types inheriting from the Joystick_observer abstract class (interface) implementing its update function and keeps them in a container. In each iteration of the main loop the update function is called for all subscribed observers with the object containing resent joystick events as its argument. This way we only need to define classes inheriting the interface and implementing update function and subscribing them. You can take a look at the code here:
So far these observer objects get updated with their update function called but in order to be able to send their data after interpreting it as desired, they also need a reference to an instance of the CPPAMQP object. As can be seen:
https://github.com/ardeshiri/joystick_service/blob/develop/src/Motor_med.cpp
and
https://github.com/ardeshiri/joystick_service/blob/develop/src/Servo_med.cpp
They use their RMQ instance to send their data to the "med" exchange with desired routing key. The values returned bu the joystick are usually ranged from -100 to 100 and most of the calculations inside update functions are to map them into the desirable range, build the correct format and to sent it in a message. There is also a makefile to compile this service. It also can be containerized but since it is going to be run on my own system I did not find it necessary.
The overall architecture of this part can be summarized in this diagram:
![]() |
| joystick service |
With this part done, the next and the last part of the first phase will be camera video transmission which I have written in python.
Arash Ardeshiri
August 2 2021

Comments
Post a Comment