First of all, we had to implement our software on the PCB. In order to do so, we connected the Arduino board to the PCB with the TX pin, the RX pin, the 5V, the ground and the reset, and we loaded the program via the USB port.
Our program was written to be the most readable as possible and commented as much as possible. It can be found here.
The main outline of the code is detailed below:
The program begins to initialize every variables, every output, input,...
For instance, the red power led is set as an output at high state (it’s turned on as long as the power supply is connected).
Besides, the motor is initialized and defined as a servo object (use of the Servo.h library) and the LCD display is define as a 4x20 screen.
This is also the part where we display the welcome messages and the instruction for the course of events.
In this part, the program will run in a loop until the user has chosen each parameter. The choice is confirmed by pushing the selection button.
First, the user chooses the level of difficulty he wants. The value is read and mapped into a value between 0 and 130 to tell the motor to which position it should go (0 being the 1st level and 130 the 10th level).
Then, the user can choose the number of exercises he/she wants to do to achieve a session (1 to 50). Now, the game mode has to be selected. There are four modes: Challenge, Reflex, Video Game and Classic (they will be explained below).
Finally, the user indicates if he/she is a man/woman, in order to decrease the difficulty of the game as it can be pretty physical (the levels of difficulty will be divided by 2).
Once everything is set up, the motor goes to its right position and the chosen game begins.
The function is continuously called to adjust the motor position depending on the current level. The servo is controlled by a PWM command (Pulse Width Modulation).
This function continuously reads the value of the linear potentiometer attached to the handle in order to display the intensity with which the user pulls it.
This function checks if an exercise is valid – if the handle is pulled far enough – and increments the quantity of done exercises. It is not called if we are in the video game mode.
When this function is call, every parameters of the game are reset and the user gets back to the selection of the parameters.
The goal of this mode is simply to achieve to number of exercises at the chosen level. When done, a message is displayed and resetGame() is called.
In this mode, the user starts at the chosen level and every time he/she achieves the number of exercises, the level increases by one. When he/she achieves the level 10, a message is displayed and resetGame() is called.
This mode is based on the same principle as the classic mode, but here, a led is used to test the vivacity of the user. In fact, the led blinks at random intervals, and if the user hasn’t pulled the handle before the led turned off, he loses one point (i.e. one exercise in the counter). When the number of exercises is reached, a message is displayed and resetGame() is called.
In this mode, the user plays a video game on the computer, using the device as a joystick. When he/she pulls the handle, an event occurs in the game. For instance, we decided to use the well-known game Mario Kart, and when the handle is pulled, the character throws a carapace, a banana,... The movement is controlled via the X and Y axis of the joystick and the acceleration is controlled via the Z axis as well as the jump. Of course, the level of difficulty is still in place and the user plays to Mario Kart with the difficulty chosen at the beginning. The user can exit this mode whenever he/she wants by pushing the selection button (resetGame () will be called).
For the simplicity of the demonstration we used an existing game, Mario Kart. But if needed, any game could run with our device, even a game created by ourselves that could use better the possibilities of the rehabilitation robot. In order to do so, the open-source SDL library would be used. You can find here an example of a small C++ program, which enables the SDL library and uses the joystick.