## 2 Materials and Methods
### Control System  
The control system was designed upon a Raspberry Pi 4 microcomputer with a server version of a Raspbian operating system (OS). Raspbian is a Linux system distribution, optimised for Raspberry Pi hardware. Our control system uses its life version--a barebones implementation, with a real-time kernel installed. Robot control is a computationally demanding task and calls for a multithreaded approach. Therefore, the processes and tasks were divided among the four processing cores of the microcomputer, based on their timing requirements, as shown in Figure 3.  
The program consists of several functionally split real-time and non-real-time processes. The real-time processes must be executed at specific time intervals, while the non-real-time processes do not require such strict timing. Therefore, the processes with similar time requirements run together on the same core. The first core is used for non-real-time processes such as high-level decision execution and OS functionalities. All other three cores are hidden from the OS interrupts and only work on their respective tasks: position and force control of the motors, communication, sensor data acquisition, and motor position tracking. Since the real-time processes managing cores are isolated from the Raspbian OS, their timing efficiency is increased. The control system was developed using the C programming language, as it allows for faster running time than other frequently used programing languages, for example, Python. The low-level control of the device includes:  
* motor position control;
* communication with patient's user interface, using Bluetooth connection;
* strain gauge based force sensors,
- incremental encoders of the motors,
- torque measurements from the motors. Motor drives, ESCON module 50/5 (maxon Group, Sachseln, Switzerland), regulate the force and velocity of the motors and enable analogue measurement of the motor's torque. An incremental position encoder is integrated into each motor, monitored by the motor driver and the assigned microcomputer core. In order to enable telerehabilitation services, connectivity is implemented via Bluetooth connection of the device with the patient's user interface. The latter is further connected to the web portal that enables thetherapist to define or modify the therapy protocol, insight into individual therapy reports, and overall rehabilitation progress and adherence. The communication with hardware peripherals is provided by using pulse-width modulation (PWM) for the motor drives and serial peripheral interface (SPI) for the analogue-to-digital converter (ADC). The control scheme includes two groups of analogue signals, torque measurements from both motor drivers, and force measurements from the future force sensor. To interpret these signals, we use 10-bit ADC circuits. The initial calibration of the device encompasses the controlled motion throughout the complete ROM in both directions. The end-positions of the joints are determined by the detection of the increased motor current values. The absolute joint position is calculated from the lower bound, counting the encoder outputs. The initialization procedure needs to be performed prior to donning; otherwise, the detection of excessive force at the distal finger rest stops the calibration process and issues an error message. The high-level control is used to set the movement boundaries, the level of assistance or resistance, and to choose between the four training modalities--passive, assisted, active, and resistive. In the passive mode, where the device is active and the patient is passive, position control is implemented using the encoder feedback and the proportional-derivative (PD) control approach. Figure 4 depicts a block diagram of such a PD control. The first inputs of the controller are the high-level decision parameters defined by the therapist--such as maximum ROM and maximum permissible force.