scieee AI-readable full text Open interactive document viewer

ROS-Based Indoor Autonomous Exploration and Navigation Wheelchair

Palau Julià, Nil

Abstract

The aim of this project is to create a platform that when implemented to an electric wheelchair could give to the users different control methods to suit their needs. It will be composed of a adaptive control system by means of different controllers and an autonomous control system. In addition, a system for measuring physiological parameters has been implemented to supervise the user?s health state when it is used sites such as hospitals, and their emotional state in order to optimize their period of adaptation to the control. It is oriented to offering people with severe disabilities, who cannot control a wheelchair by themselves, independent mobility from their caregivers in indoor spaces. The control platform has the objective to be as economic as possible and adaptable to any electric wheelchair model.

Full text

Final Project of the Bachelor’s Degree in Engineering Physics ROS-Based Indoor Autonomous Exploration and Navigation Wheelchair Nil Palau Juli`a Thesis director ` Oscar Casas Piedrafita Instrumentation, Sensors and Interfeces Group Universitat Polit`ecnica de Catalunya June 27, 2022 Nil Palau Juli`a ROS-Based Indoor Autonomous Exploration and Navigation Wheelchair Bachelor’s Degree Final Project, June 27, 2022 Thesis director: ` Oscar Casas Piedrafita Polytechnic University of Catalonia Bachelor’s Degree in Engineering Physics Barcelona School of Telecommunications Engineering C/Jordi Girona, 1-3 08034 Barcelona ACKNOWLEDGEMENT First, I would like to thank Prof. Oscar Casas for letting me work on this interesting project. From the beginning it has given me all the support I need and has always been available for any questions or concerns I may have. Also I could see how professional and good a person he is. That is why I am so grateful. I also want to express my gratitude to Jeff Guifo for his collaboration on the thesis, helping me in some parts of the project and teaching me how to use ROS; to Maria Delgado for providing me with all the necessary resources previously used in her project; and to Francis Lopez for helping me in hardware integration. Finally, I would like to thank ASPACE and Angel Aguilar for collaborating on the project and let me use their facilities and the wheelchair. RESUM L’objectiu d’aquest projecte ´es crear una plataforma que, un cop implementada a una cadira de rodes el`ectrica, pugui proporcionar als usuaris diferents m`etodes de control que s’adaptin a les seves necessitats. Aquesta estar`a composta per un sistema de control adaptatiu, mitjan¸cant diferents controladors, i un sistema de control aut`onom. A part, tamb´e s’ha implementat un sistema de mesura de par`ametres fisiol`ogics que permet supervisar l’estat de salut de l’usuari quan es fa servir en llocs com hospitals, i l’estat emocional per tal de poder optimitzar la seva fase d’adaptaci´o al control. Est`a orientat a oferir a les persones amb discapacitats greus, que no poden controlar per elles mateixes una cadira de rodes, mobilitat independent dels seus cuidadors en espais interiors. La plataforma t´e l’objectiu de ser adaptable a qualsevol model de cadira de rodes el`ectrica i ser el m´es econ`omica possible. La tesi es realitzar`a mitjan¸cant ROS, que ´es un sistema operatiu que permet desenvolupar sistemes de control aut`onoms, disposant d’una gran varietat de biblioteques i eines pel que fa a softwares de mapejat i navegaci´o. Tamb´e s’utilitzaran altres programes com Matlab i Arduino, i diversos dispositius electr`onics com sensors inercials, c`ameres de profunditat, microprocessadors, microcontroladors, dispositius de seguiment ocular i altaveus intel·ligents. A m´es, gr`acies a ASPACE, la cadira de rodes Quantum Q4 estar`a disponible per realitzar les proves necess`aries. Al final del projecte, s’ha aconseguit crear una arquitectura de control de baix cost implementable a qualsevol model de cadira de rodes el`ectrica. S’ha pogut comprovat amb `exit el correcte funcionament del sistema de control adaptatiu, el sistema de control autom`atic i el sistema de mesura de par`ametres fisiol`ogics, el quals conformen la totalitat de la plataforma de control. OVERVIEW The aim of this project is to create a platform that when implemented to an electric wheelchair could give to the users different control methods to suit their needs. It will be composed of a adaptive control system by means of different controllers and an autonomous control system. In addition, a system for measuring physiological parameters has been implemented to supervise the user’s health state when it is used sites such as hospitals, and their emotional state in order to optimize their period of adaptation to the control. It is oriented to offering people with severe disabilities, who cannot control a wheelchair by themselves, independent mobility from their caregivers in indoor spaces. The control platform has the objective to be as economic as possible and adaptable to any electric wheelchair model. The thesis will be carried out using ROS, which is an operating system that allows to develop autonomous control systems, having a wide variety of libraries and tools in terms of mapping and navigation software. Other programs such as Matlab and Arduino, and various electronic devices such as inertial sensors, depth cameras, microprocessors, microcontrollers, eye trackers and smart speakers will also be used. In addition, thanks to ASPACE, the Quantum Q4 wheelchair will be available to perform the necessary tests. At the end of the project, it has been achieved to create a low-cost control architecture implementable to any electric wheelchair model. The correct operation of the adaptive control system, the automatic control system and the system for measuring physiological parameters, which make up the entire control platform, has been checked successfully. ACRONYMS ASPACE - Associaci´o de Par`alisis Cerebral BPM - Beats Per Minute DOF - Degrees of Freedom ECG - Electrocardiogram ECU - Electronic Control Unit EEG - Electroencephalogram EMG - Electromyography HR - Heart Rate HRV - Heart Rate Variability IMU - Inertial Measurement Unit IPG - Impedance Plethysmogram IR - Infrarred LED - Light Emitting Diode LIDAR - Light Detection and Ranging mCU - Microcontroller OpenCV - Open Computer Vision PPG - Photoplethysmography ROS - Robot Operating System SCL - Serial Clock Pin SDA - Serial Data Pin SDNN - Standard Deviation of NN(or RR) intervals SLAM - Simultaneous Localization and Mapping UPC - Polytechnic University of Catalonia USB - Universal Serial BUS CONTENTS 1. INTRODUCTION AND OBJECTIVES 1 2. STATE OF THE ART 2 3. ARCHITECTURE 4 3.1. Platform model 4 3.2. Hardware review 5 3.2.1. Microprocessor 5 3.2.2. Microcontroller 6 3.2.3. Electronic control unit 7 3.2.4. Sensors 8 3.2.5. Control architecture 9 4. ADAPTIVE CONTROL 10 4.1. Joystick controller 10 4.2. Voice controller 11 4.3. Eye tracking controller 12 4.4. Control interface 12 5. AUTOMATIC CONTROL 14 5.1. Software review 14 5.1.1. Mapping and navigation software 14 5.1.2. Operating system 15 5.2. Odometry 16 5.2.1. Position measuring device 16 5.2.2. Inertial sensor 20 5.3. Mapping 37 5.3.1. ROS SLAM algorithms 38 5.3.2. Mapping platform 38 5.4. Navigation 40 6. CHARACTERIZATION WHEELCHAIR USER PERFORMANCE 43 6.1. Acquisition system 43 6.2. Experimental results 44 6.3. Implementation 46 7. EXPERIMENTAL RESULTS AND EXPERIENCE IN ASPACE 49 7.1. ASPACE sessions 49 7.1. Experimental results in the laboratory 51 8. CONCLUSIONS AND FUTURE WORK 54 REFERENCES 56 ANNEX A 61 A.1. Inertial sensor quality measurements under antivibration static conditions 61 A.2. Kalman filters 64 A.3. Euler angles 66 ANNEX B 67 B.1.1. Control architecture 67 B.2.1. Control interface 68 B.3.1. Static orientation estimation plots 70 B.3.2. Dynamic orientation estimation plots 73 B.3.3. Position estimation plots 77 B.4.1. ECG Poincar´e Plots 81 ANNEX C 82 C.1. Control platform cost 82 ANNEX D 83 D.1.1. Adaptive control Arduino codes 83 D.1.1.1. Controllers’ code (Arduino Due) 83 D.1.1.2. Wifi command reception code (AZDelivery ESP32) 89 D.2.1. BNO055 sensor data capture Arduino code 92 D.2.2. Orientation estimation Matlab code 94 D.2.3. Position estimation Matlab code 97 D.2.4. Rotatory encoder Arduino code 100 D.2.5. Automatic control codes 102 D.2.5.1. Navigation ROS code 102 D.2.5.2. ECU control Arduino code 106 D.2.5.3. Odometry sensors data Arduino code 108 D.3.1. ECG parameters Matlab code 112 1. INTRODUCTION AND OBJECTIVES Wheelchairs have evolved over time in order to provide better performance and greater comfort in the daily lives of people with motor disabilities. Today there are electric wheelchairs that allow the users to move wherever they want. But still, there are people who are not able to control these wheelchairs on their own, as is the case of people with cerebral palsy. That is why the aim of this project is to create an external system that when implemented to any electric wheelchair model could offer to the users different control methods to suit their needs. From adaptive controllers, where the users are the ones who control the wheelchair at all time, to an automatic control, where the users can select the location where they want to go and the system will be able to create a route and save the possible obstacles that the wheelchair could find in its trajectory. All this, under the supervision of a system that allows to monitor their health and emotional state from the measurement of physiological parameters, thus being able to detect if they feel comfortable during navigation. At the time of creating the control platform, it will be sought to be low-cost and as lightweight and comfortable as possible, so that it can be easily installed. Also, it is very important that the system is external to the wheelchair, so that it has enough versatility to be able to be implemented in any electric wheelchair model. Finally, it should be noted that the platform will be developed for indoor navigation. The project will be carried out in collaboration with the Cerebral Palsy Association (ASPACE), which will allow the access to its facilities and the Quantum Q4 wheelchair. Initially, the objective was only the development of a control architecture for autonomous navigation, hence the name ”ROS-Based Indoor Autonomous Exploration and Navigation”. But after talking to ASPACE and seeing the needs of users, it was decided to create also an adaptive control architecture and a system for measuring physiological parameters. The thesis is structured in 7 chapters that follow the evolution of the project: Chapter 2 is dedicated to studying the state of the art of electric wheelchair navigation; Chapter 3 presents the control platform designed and the hardware used to develop it; Chapter 4 shows the structure of the adaptive control system with the corresponding controllers designed; Chapter 5 is dedicated to the autonomous control system, where its structure, software and the different components used will be presented; Chapter 6 is based on the development of a system for measuring physiological parameters to characterize wheelchair user performance; Chapter 7 will cover the experimental results and the different tests performed with the wheelchair in the sessions at ASPACE; and finally, Chapter 8 will expose the conclusions of the thesis and future work. 1 3.2.4. Sensors This part of the architecture is the one that will allow to receive information about the wheelchair and its environment, which will be essential for automatic control. As will be seen in section 5.2, an inertial sensor and a rotary encoder are needed in order to be able to measure wheelchair odometry correctly. On the one hand, the BlueDot BNO055 inertial sensor is to be able to measure orientations accurately using Euler angles. On the other hand, the DFROBOT SEN0230 rotary encoder allows to measure distances also with great precision. That is why, with a combination of the two devices, an odometry system can be obtained that provides the orientation, the position and the velocity of the wheelchair over time. Company Device Measurement Parameters BlueDot BNO055 IMU Orientation (Euler angles) Farnell SEN0230 Rotatory Encoder Displacement and velocity (linear and angular) Table 4: Odometry devices As will be seen later, in order to be able to perform automatic control and navigate autonomously, it is essential to have a mapping of the environment in which the wheelchair will move. Therefore, apart from an odometry system that allows to measure orientations and displacements, it is also needed a device that allows to do the mapping. In this way, the control system requires the incorporation of a depth camera or a laser scan camera. In Table 5 there is a summary of the most common commercial camera sensors. Company Sensor type Device Asus Depth Xtion PRO Live Microsoft Depth Azure Kinect Microsoft Depth Kinect XBOX 360 Intel Depth RealSense D435 Intel Laser scan RealSense L515 Leica Geosystems Laser scan Leica BLK360 Table 5: Camera sensor possibilities In this project, considering the price, the compatibility and its functionalities the device that has been used is the Kinect XBOX 360. Later, in the automatic control, it will be seen the compatibility and functionality requirements that have been considered to make this choice. Figure 7: Microsoft Kinect XBOX 360 8 3.2.5. Control architecture Now, after seeing the devices used, the architecture of the platform is as follows: Figure 8: Platform architecture This architecture is quite simple. First of all there is the LattePanda computer board, which is connected to the Arduino Due board through the serial port to receive and send commands. This board is connected to an 8-relay module, where each relay corresponds to an Arduino Due output pin. The 8-relay module is used to safely withstand higher electrical loads and not damage the internal electrical system of the wheelchair in case of a fault. Each channel of the module is connected to a LED that indicates the switching status of the relay. Arduino Due is also connected to ESP32 board, which is used to transmit to the Arduino Due the commands that are sent via Bluetooth or WiFi connection. Except the LattePanda, all these devices are contained in a box (Figure 12), which is adapted so that all connections to them can be accessed. The outputs of the box are eight different Jack connectors, where each one of them corresponds to one of the relays. And, with Jack-to-Jack wires, the box is connected to the wheelchair ECU. Figure 9: Microcontroller box Furthermore, connected to LattePanda computer board, there is also the Kinect XBOX 360 and another Arduino Due, which receives the data provided by the BNO055 inertial sensor and the rotatory encoder SEN0230. This part of the hardware is the one that is used to calculate odometry and do the mapping that will allow the autonomous navigation of the wheelchair. This architecture is designed to be versatile, so that all devices and their respective connections are accessible in order to be able to be modified or extended in future work. In Annex B.1.1. can be seen a diagram of the devices and connections made in the creation of the control platform hardware. 9 4. ADAPTIVE CONTROL In order to control the wheelchair ECU, the control system act as a set of switches, where each one of box outputs correspond to one command. In this case, it is needed four commands, which are: forward, backward, right, and left. Therefore, only four of the box outputs and four of the relays are used. There is also a fifth command: stop, which shuts off all relays. From here, assigning each output to one of the specific directions, the wheelchair can be controlled by choosing at any time which of the four relays is on. In this case, as it is a adaptive control [13], the action of a person who closes the control loop is necessary. So the difficulty lies in knowing what is the best control method to turn on and off switches considering the physical and mental difficulties that people with cerebral palsy suffer. And that is why a multi-parametric control has been developed by designing three controllers types: joystick controller, voice controller and eye tracking controller. [3][7] Figure 10: Adaptive control loop 4.1. Joystick controller The first controller consists of a dual-axis XY joystick compatible with Arduino. The joystick has a total of four connections, two of which correspond to voltage supply and ground and two of which correspond to the potentiometers that define X and Y directions. The potentiometer values are read through two analog pins of the Arduino DUE, which allows the board according to the reading values to know which direction is being indicated at any given time and turn on the corresponding relay. An alternative to this controller would be to use an inertial sensor, which when moved by the person could act as a joystick by reading the values provided by the accelerometers. In addition, in this case a generic joystick has been used, but an adapted joystick for motion detection of the chin, head or mouth could also be implemented. 10 4.2. Voice controller The second controller consists in a voice system. In this case it is necessary to implement a new device that serves as a voice-controlled virtual assistant. In Table 6 there is a summary of the most common commercial virtual assistants. Brand Developer Device Alexa Amazon Amazon Echo Siri Apple HomePod Google Assistent Google Google Home Cortana Microsoft Invoke Bixby Samsung Samsung Galaxy S Table 6: Voice-controlled virtual assistants In this project, it has been opted for Alexa virtual assistant, using the Amazon Echo Dot device. This choice has been made on the basis that Alexa is the voice assistant that shows the greatest compatibility with other devices, whether they are from Amazon or from other companies. In this way, Amazon is the brand that offers greater freedom when working with its products. In addition, some ASPACE users already have previous experience using voice assistants such as Alexa. Using the Alexa mobile phone app available for Android and iOS, the Echo Dot device can be configured and the necessary commands can be created so that they can be sent to other compatible devices via voice control. In order for the devices to communicate with each other, they must be connected to a WiFi network, and that is why the ESP32 board has been incorporated into the control system. This board allows us to receive the orders from the Echo Dot, to later transmit them to the Arduino Due, which controls the relays state. Figure 11: Amazon Echo Dot The Echo Dot voice commands are: ”Alexa, adelante” (forward) ”Alexa, atr´as” (backward) ”Alexa, izquierda” (left) ”Alexa, derecha” (right) ”Alexa, para la silla” (stop) Voice commands have been tested by different users and in all cases the voice assistant has been able to recognize users’ voice and execute the orders with no problem. 11 4.3. Eye tracking controller The last controller consists in an eye tracking system. So obviously, it has been necessary to incorporate to the control system an eye tracking device. In Table 7 there is a summary of the most common commercial eye trackers. Brand Device Tobii PCEye SMI SMI Eye Tracking Glasses Gazepoint Gazepoint GP3 Smart Eye Smart Eye Al-X Pupil Labs Pupil Invisible Table 7: Eye tracking devices Considering the price, the accessibility and its functionalities the device that has been used is the Tobii PCEye. In addition, this device is the one used by ASPACE users for eye tracking, so they have previous experience controlling it. The only problem is that this device is compatible with Windows (10 & 11) and MAC OS X, but not with Linux, so the eye tracking controller cannot be used if this last operating systems is used. In this case, to control the relays state, a control interface has been created in which to select the commands by eye tracking. Figure 12: Tobii PCEye 4.4. Control interface Since a control interface is required for the eye tracking controller and the interactivity with the wheelchair should be as understandable and accessible as possible for people with cerebral palsy, what has been done is to create a control application. To create the control application the Visual Studio program has been used. This program has the Windows Forms App feature, which allows to create interfaces using C# language. In addition, it is compatible with Arduino, so that through the serial port the App can communicate with Arduino boards, sending and receiving orders. In order to communicate the application with the Arduino board, what has been done is to print specific words on the serial port, so that these are stored in a string on the microprocessor of the board, which can read the word and run the corresponding order specified in its code. From here, once the three controllers have been designed, the next challenge has been to make it possible to choose at any time which one to use. 12 To do this, the application has been created with a total of four forms (interfaces): one interface corresponding to the start-up screen and three interfaces corresponding to each of the controllers. First, there is the start-up screen, where the serial port is configured and the adaptive controller type is selected. Here, the application has a specific word for each one of the controllers that when are selected it is written to the serial port and the corresponding controller interface is open. At this point, the three Arduino codes for the controllers have been fused in one, being every one of the three controllers a case inside the code. So, when the word written by the startup screen is read by the Arduino board, this one activates the corresponding case associated to that word. Also, in controllers interfaces there is a return button that reopens the start-up screen, closing the controller that was being used and allowing the controller to be selected again. Therefore, this control application allows to select any time the controller that is wanted to use without having to do any modification in the software and hardware when changing the controller. Note that no more than one controller can be used at the same time. In terms of design, the interfaces have been created in such a way that they are as understandable and easy to use as possible, making the buttons large and well distributed on the screen and using support images (Figure 13). In addition, the interface has been tested by some ASPACE users, who have approved the design. In terms of compatibility, this application can be used almost entirely in any operating system. The only problem lies in the use of the eye tracking controller, because as the Tobii PCEye is only compatible with Windows 10 or 11 this functionality is restricted to this operating system. The application interfaces can be seen in Annex B.2.1. Also, in Annex D.1.1. there are the Arduino codes used for the adaptive control. Figure 13: Eye tracking controller interface 13 5. AUTOMATIC CONTROL For this control, since it is automatic, the action of a person who closes the control loop is not necessary, as it is the different sensors that perform this work. This is why it is necessary to implement a software that can execute commands autonomously from the data provided by the BNO055 sensor, the SEN0230 rotary encoder and the Kinect XBOX 360, thus creating the mapping and performing the navigation. Figure 14: Automatic control loop 5.1. Software review 5.1.1. Mapping and navigation software In order to be able to create the automatic control first it is necessary to choose which software will be used for the mapping and the navigation. As can be seen in the state of the art, the two most used softwares today in robotics applications are Open CV and ROS. — Open CV (Open Computer Vision). It is an open source library that has a wide range of applications, such as robotics, facial recognition, augmented reality, and gesture recognition, among others. Therefore, it offers different possibilities in terms of mapping and navigation. This software is compatible with the main operating systems (Linux, Mac OS X, Windows, iOS and Android) and programming languages (Phyton, Java, C and C++). [14] — ROS (Robot Operating System). It is a set of open-source libraries and tools to help software developers to create robot applications. It provides hardware abstraction, device drivers, libraries, visualization tools, messaging, package management, and more. This software is compatible with the Linux operating system and it uses Python, C++ and Lisp programming languages. Today, ROS 2 has been developed, offering the possibility of being used in Windows and Mac OS X as well. [15] 14 In terms of mapping and navigation, ROS is by far the most widely used software, as it offers a wide range of functions and applications in robotics. In addition, it has a large community behind, having many forums with possible solution to upcoming problems. And also, it exist the corresponding drivers for the Kinect XBOX 360 and the BNO055 inertial sensor. That is why in this project it has been decided to work with ROS. ROS is designed to be a loosely coupled system where a process is called a node and every node should be responsible for one task. Nodes communicate with each other using messages passing via logical channels called topics. Each node can send or get data from the other node using the publish/subscribe model. [16] Figure 15: ROS operation diagram There exist different ROS distributions, which are a versioned sets of ROS packages created with the purpose to let developers work against a relatively stable codebase. These ROS distributions are: Distribution Linux version ROS Noetic Ubuntu 20.04 (focal) ROS Melodic Ubuntu 18.04 (Bionic) ROS Kinetic Ubuntu 16.04 (Xenial) Table 8: ROS distributions 5.1.2. Operating system Once it has been chosen the software that will be used for mapping and navigation, it has also to be chosen the operating system. Initially, it was decided to use ROS 2 on Windows. This is because since the adaptive eye tracking controller is not compatible with Linux, this would make it easier to create a mixed control in the future. However, the drivers of the Kinect XBOX 360 do not work properly in ROS 2 on Windows, so it has finally been decided to use the Linux operating system. The Linux version used has been Ubuntu 16.04. This version is the oldest one but it is still supported, having a lot of forums with possible solution to upcoming issues. Also, its corresponding ROS distribution (Kinetic) is the most used for autonomous wheelchair projects and it has good compatibility with Kinect XBOX 360 drivers. 15 5.2. Odometry One of the most important things about creating the automatic control is having a measurement system that allows to calculate the odometry of the wheelchair over time. That is, a system to be able to locate the position of the wheelchair on a map. This would have an easy solution if having access to the wheel encoders, but it is not the case. Also, as it was tested in [9], getting information from the electrical control unit is not a good option either, as the real behavior does not look like the calculated one because it strongly depends on the weight and battery of the wheelchair. For this reason, it has been decided to create an odometry system external to the wheelchair. Its development has a great advantage, which is that as it is external it will be able to be implemented to any wheelchair model. 5.2.1. Position measuring device 5.2.1.1. Device selection To get started, it is important to see what possible devices can be used to create the odometry system. So, the following ones have been proposed: — Infrared emitter and receiver pair. By fixing an IR transmitter pointing at the wheel and several receivers on the wheel, it will be possible to count the turns made by the wheel. — Reed switch and magnet pair. The same as before but working with magnetic fields. A reed switch would be fixed and pointing to the wheel and several magnets would be placed in the wheel. — Rotary encoder. By fixing the encoder on the axis of the wheel, this device can convert the axis movement into a pulse signal proportional to the rotation of said axis. All of these options are good in terms of price and accessibility, as there is a wide variety of commercial products. But, with regard to the reed switch and magnet pair and the infrared emitter and receiver pair, it is necessary to place several receivers and magnets on the wheel in order to be able to achieve a high accuracy in the measurements. That is why in this project it has been opted to use a rotatory encoder. 16 5.2.1.2. Rotary encoder From here, once it has been decided to use a rotary encoder, a number of options have been sought and listed in Table 9. Brand Manufacturer Device Signswise Signswise Optical Rotary Encoder Farnell DFROBOT SEN0230 Photoelectric Rotary Encoder Aihasd AX Electronic Optical Rotatory Encoder Omron Omron Rotatory Encoder E6A2-C Table 9: Rotatory encoder devices Finally, due to its low cost, high Arduino compatibility and brand reliability, the rotary encoder selected is the DFROBOT SEN0230. Table 10 shows the properties of the device. Device Properties DFROBOT SEN0230 Signal: AB two-phase orthogonal pulse signal though axis rotation Resolution: 400 pulses/round Max speed: 5000 r/min Supply voltage: 4.8-24 V Compatible with Arduino, STM32 and PLC Table 10: DFROBOT SEN0230 Photoelectric Rotatory Encoder properties [24] 5.2.1.3. Position and velocity measurement accuracy In order to measure displacements and velocities, the encoder can be implemented in two different ways (Figure 16): By fixing the encoder on the wheel axis As seen in the properties, the rotary encoder used has a resolution of 400 pulses/round. This is equivalent to: Resolution =360◦ 1round ·1round 400pulses = 0.9◦ From here, it is known that the wheels of the wheelchair have a radius of 17cm, so if the encoder is fixed on the wheel axis, the resolutions of the average linear velocity and the displacement in a time interval are: Displacement resolution 1=0.9◦·π rad 180◦·170mm = 2.67mm Average linear velocity resolution 1 = Displacement resolution ∆t=2.67 ∆t mm s 17 Looking at Figure 64 and Figure 65 it is not a bad approximation to consider the error as a normal distribution, the parameters of which for each of the magnitudes are as follows: Linear acceleration (m/s2) Mean Standard deviation X−axis 0.006 0.008 Y−axis 0.009 0.009 Z−axis −0.303 0.017 Table 12: Normal distribution parameters for linear acceleration errors Angular velocity (rad/s) Mean Standard deviation X−axis 0.002 0.135 Y−axis 0.001 0.165 Z−axis 0.008 0.066 Table 13: Normal distribution parameters for angular velocity errors WitMotion WT901C485 IMU If the previous process is repeated with this other sensor the results are the following ones: Figure 25: Linear acceleration measurement under static conditions In this case the measured accelerations have the same behavior as in BlueDot BNO055 sensor. But in terms of angular velocity the values provided by the Witmotion software are ideal, being all zero. Therefore, only the errors corresponding to the linear accelerations have been characterized. 24 Figure 26: Linear acceleration histogram under normal static conditions Linear acceleration (m/s2) Mean Standard deviation X−axis −0.067 0.003 Y−axis −0.008 0.009 Z−axis −0.008 0.004 Table 14: Normal distribution parameters for linear acceleration errors From the values in Table 12 it can be seen that the BNO055 sensor obtains an average linear acceleration value of the order of the thousandths for the X and Y axis and of the order of the tenths for the Z axis. A similar thing can be seen from Table 13, being the average angular velocity of the order of the thousandths in almost all cases. As for WT901C485 sensor, angular velocity results provided are ideal. Regarding accelerations, from Table 14, average values of the order of the hundredths for the X axis and of the order of the thousandths for the Y and Z axes are observed. Therefore, after these analyzes, it can be seen for both sensors that the error measurement seem to be small, especially for WT901C485 sensor, which has performed better. 25 5.2.2.3. Static orientation estimation Next, what will be done is to use Euler angles (see Annex A.3.) to see how good are the sensors when estimating orientations under normal static conditions. That is why five-minute static samples under normal conditions have been used to perform the analysis. Euler angles are not a direct measurement parameter in inertial sensors, but are calculated from other physical magnitudes such as acceleration, angular velocity, and magnetic field. In both sensors, this calculation is performed by its internal algorithm, which provides the estimated value of each angle. For both sensors, Euler angles calculated remain constant over time (see Annex B.3.1.). Therefore, given that the measurements are static, the results obtained are ideal. So at the moment it seems that the internal algorithm of the sensors correctly estimates the angles. Despite the good results obtained, attempts have also been made to calculate Euler angles using an external algorithm, which uses the values of the physical magnitudes measured by the sensor. The algorithm uses the ahrsfilter and imufilter from Matlab commands. These commands consist in a Matlab System Object that fuses accelerometer, magnetometer and gyroscope sensor data to estimate device orientation (see Annex D.2.2.) [22]. In the case of imufilter it only fuses accelerometer and gyroscope sensor data. That is, ahrsfilter uses 9 degrees of freedom and imufilter uses 6 degrees of freedom. As might be expected, the results obtained using 9 degrees of freedom are better than those obtained in the case where 6 degrees of freedom have been used (see Annex B.3.1.). For the Witmotion sensor, Euler angles remain constant over time (Figure 27) as in the previous case. But regarding to BNO055, as seen in 29, Euler angles seem to remain constant over time but with some dispersion. That is why a low-pass filter has been applied to the algorithm to try to correct this (Figure 29). Figure 27: Euler angles calculated from WitMotion WT901C485 data (using 9DOF) 26 Figure 28: Euler angles calculated from BlueDot BNO055 data (using 9DOF) Figure 29: Euler angles calculated from BlueDot BNO055 data (using 9DOF) after applying a low pass filter Once the low pass filter is applied the results have improved. However, for both sensors the values provided by their internal algorithm are more accurate than those calculated externally. Therefore, from now, the Euler angles provided by the sensor internal algorithm will be the ones used to define the orientation. 27 5.2.2.4. Dynamic orientation estimation At the moment, both sensors have been shown to accurately measure Euler’s angles in static conditions. Now, however, it remains to be seen whether this is still the case when the sensors are in motion. 5.2.2.4.1. X, Y, Z axis rotations To begin with, a first analysis of the sensors has been made in order to study their behavior when they are rotating on one of their axes. It should be noted that the reference position of the sensor is always with its Z axis pointing towards the center of the Earth. BlueDot BNO055 IMU For this sensor, the analyzed motion, which have been done for each one of the axes, consists of a clockwise rotation of 360◦followed by a counterclockwise rotation of 360◦. And the results obtained are as follows: Figure 30: Euler angles from a rotational movement of the X-axis Figure 31: Euler angles from a rotational movement of the Y-axis 28 Figure 32: Euler angles from a rotational movement of the Z-axis Figures 30, 31 and 32 show the behavior of the three Euler angles under the action of a rotational motion of the sensor on each of its axes. Taking into account the movement made, in each case the ideal would be to observe how the Euler angle corresponding to the axis on which the rotation has been made varies its value from 180◦to −180◦, and how the two others remain constant. In addition, if the behavior of angular velocities and accelerations is observed (see Annex B.3.2.), what should happen is that angular velocities are only detected on the axis in which the rotation occurs, and that for accelerations only gravity is detected. In the case of gravity, if the sensor is in a rotation on the Z-axis it should remain on the Z-axis, if the sensor is in a rotation on the X-axis it should be distributed on both Y-axis and Z-axis and if the sensor is in a rotation on the Y-axis it should be distributed on both X-axis and Z-axis. So, knowing the logical behavior that should be obtained, it is seen how the BNO055 sensor obtains the best results when it is rotating on the Z axis. Actually, with only one Euler angle working properly it is enough, as the movement of the wheelchair will be in two dimensions and therefore considering this plane the X-Y plane the orientation can be defined with only the Euler angle Z. 29 WitMotion WT901C485 IMU Now the previous process is repeated but with the WitMotion sensor. In this case rotations consist only of a 360◦turn. And the results obtained are as follows: Figure 33: Euler angles from a rotational movement of the X-axis Figure 34: Euler angles from a rotational movement of the Y-axis Figure 35: Euler angles from a rotational movement of the Z-axis 30 Looking at the Figures 33, 34 and 35 , it can be seen how in this case the sensor does not estimate the Euler angle Z well when it is rotating on the Z-axis. But what does seem to estimate well is the Euler angle X when it is rotating on the X-axis. Also, when the sensor rotates on this axis, good results are obtained in the measurement of acceleration and angular velocities (see Annex B.3.2.). Therefore, taking into account the movement of the wheelchair what could be done would be to place the sensor so that it is the X-axis that points to the center of the Earth, and thus all the orientations of the wheelchair could be defined with Euler angle X, which in reality will be the Euler angle Z in the reference coordinates system. However, the sensor does not have good reads at the time it is positioned so that the Z-axis of its reference system is associated with another axis that is not the Z-axis of the sensor. An example of this malfunction can be seen in Figure 36, where the sensor is in two different orientations that differ 180◦from each other and the Euler angles Z it detects are 0.83◦and 120.11◦. It could be due to the fact that its internal algorithm does not process correctly on which axis gravity is located and therefore does not compensate it well. If this were the only problem, it could be removed as it would be a systematic error. But this is not the case, as it has also been seen how the magnetic field has too much influence on the algorithm that estimates Euler angles. Figure 37 shows how the mere presence of a mobile phone near the sensor causes a change in the reading of the Euler angles. Figure 36: Euler angle Z measurement of two sensor orientations that differ 180◦ Figure 37: Euler angle Z measurement of one same sensor orientation with and without the presence of a mobile phone 31 5.2.2.4.2. Rotation + translation movements By now, it has been shown that both sensors have behaved ideally when in normal static conditions. However, this has not been the case when the sensors rotate on one of its axes, where the WitMotion sensor have had several problems. Nevertheless, with regard to the BNO055 sensor, it has been observed that it gives good results when it rotates on its Z-axis, pointing this one towards the center of the Earth. Therefore, since, as explained above, the orientation of the wheelchair can be defined with a single Euler angle, the orientation estimation analysis will be continued but focusing only on the Euler angle Z estimation from the BNO055 sensor . From here, what has been done is to study the behavior of the sensor by making rotational and translation movements on the X-Y plane (considering the Z angle of the reference system of the sensor pointing towards the center of the earth). Two analyzes have been performed in this case: a first which consists on the sensor moving two turns around a square measuring 2mx2m, and a second which consists on the sensor moving one turn around a 50cm diameter circumference making a small stop every 30◦. And the results obtained are as follow: Figure 38: Orientation estimation of a square-shaped movement in the X-Y plane Figure 39: Angular velocity of a square-shaped movement in the X-Y plane 32 In this case, it is seen in Figure 38 that the angle that varies along the motion is the Z angle, keeping the other two Euler angles constant, which is what was expected. Also, as it is a square-shaped movement it is supposed to see that the Euler angle Z experiments variations of 90◦. Therefore the sensor has a good behavior, as it measures a time interval where the angle is constant, which corresponds to the sensor moving on one side of the square, followed by a time interval in which it is measured approximately a 90 degrees variation , which corresponds to the sensor rotating in one of the corners. And this process is repeated a total of eight times, which corresponds to the eight sides and eight corners that the sensor must go through when it does two turns along the square. In addition, Figure 39 shows the eight peaks of angular velocity measured due to the turns that occur at the corners. Figure 40: Orientation estimation of a circular move in the X-Y plane making stops every 30◦ Figure 41: Angular velocity of a circular movement in the X-Y plane making stops every 30◦ In this second case, as it can be seen in Figure 40, the sensor measures a time interval in which approximately a 30◦variation has occurred, which corresponds to the sensor circular movement between stops, followed by a time interval where the angle is constant, which corresponds to the sensor stops. And Figure 41shows the twelve peaks of angular velocity measured due to the time intervals where the sensor is moving 30◦around the circumference until it makes a complete turn. 33 5.4. Navigation Once the map is done, the next step is to create the navigation platform: Figure 46: Navigation platform First of all, in order to navigate autonomously, it must be selected on the map the current position in which the wheelchair is and the target destination that is wanted to reach. From here, the move base package does the path planning task [32]. Path planning for mobile robot consist in to determine sequence of manoeuvres to be taken by robot in order to move from starting point to destination avoiding collision with obstacles. The algorithms that the move base uses are: — Costmap 2D. The costmap holds information of obstacles or areas that the vehicle cannot traverse. Then, it generates a 2-D grid of cells where each cell has a value representing the cost of navigating through that cell, obtaining an occupancy map. Finally it shows where the robot should navigate to reach the destination optimizing the cost of the route. — Base local planner. It is responsible for generating velocity commands to send to the wheelchair given a plan to follow and a cost map. First, it makes discrete samples of the robot’s environment. For each sampled velocity, simulate the next state of the robot in order to predict the consequences of applying that sampled velocity to the robot for a short time lapse. Then, evaluates the results of each trajectory and discard the ones that are not possible (those that collide with obstacles). The metrics used for evaluation comprise proximity to obstacles, proximity to the goal and speed. Finally, the velocity associated with the higher scored trajectory is sent to the robot. 40 At this point, path planning algorithm provides the velocity (cmd vel) that the wheelchair should have at all times to reach its destination. In this case, the velocity vectors needed are: — X linear velocity (Vx). The wheelchair has a 2D motion (no Z linear velocity) which is only longitudinal, it cannot move transversely (no Y linear velocity). — Z angular velocity (Wz). Motion is in the XY plane, so rotations occur only on Z axis. Then, this velocities are sent to an Arduino board. To do this, the rosserial package is used, which is a ROS protocol aimed at point-to-point communications over a serial transmission line. It allows to create ROS nodes that can access client ports, including Arduino. From here, using the velocities received, the Arduino board can calculate the velocity of each of the wheels: Vright =Vx+Wz·L/2Vleft =Vx−Wz·L/2 Where L is the distance between wheels. Note that Vxand Wzare vectors, so their sign depends on whether the wheelchair moves forward or backward and on whether it rotates clockwise or counterclockwise. Figure 47: Left: Wheelchair possible movements. Right: Wheelchair velocities example Next, depending on the compute values the Arduino board decides which of the relays (forward, backward, right, left) is ON, thus controlling the wheelchair ECU and performing the navigation. Direction Criterion Forward Vright =Vleft >0 Backward Vright =Vleft <0 Left Vright > Vleft Right Vright < Vleft Stop Vright =Vleft = 0 Table 18: Velocity criterion for selecting direction The wheelchair ECU have certain velocities programmed, so that regardless of the velocity received by the Arduino, the wheelchair will go in the right direction but at its own velocity. Also, its programmed velocities are not always the same, as they vary depending on weight and battery. This problem is what happened in [9], where the calculated wheelchair behavior was not the same as the real one, since the computed velocities where not the ones execute by the wheelchair. 41 To correct this, the odometry system is used. Once the wheelchair is navigating, the encoders and the IMU capture information of the movement. This data, is published in the topic sensors data by the Arduino board. As before the rosserial package is used to communicate Arduino with ROS. Then the node compute odometry subscribe to the topic and, as the name says, computes the odometry (See Section 5.2. and Annex D.2.5.). Finally the node publishes the values in the topic odometry. From here, with this calculated odometry the actual position in which the wheelchair is located is established and, then, the whole previous process is executed again. The execution frequency of the loop is large compared to the velocity of movement of the wheelchair. In this way, the velocity difference should not cause any problems as the position of the wheelchair will be corrected before it deviates clearly from the established trajectory. At the same time, the AMCL package is used. It is a probabilistic localization system from 2D mobile robots, which implementation comprises a particle filter [33] to track the current pose of the robot in a known map. In other words, it uses the odometry to place the robot in the map in real time. In the map, the robot appears with a particle cloud. This cloud, formed by red arrows, represents the localization system’s uncertainty about the robot’s pose. A cloud that spreads out a lot reflects high uncertainty, while a condensed cloud represents low uncertainty. (See Figure 48) Figure 48: Map of the ISI group laboratory. Red arrows represents the particle cloud and green line the route to follow to reach the destination. Finally, the Kinect XBOX 360 offers the possibility to detect real team obstacles that not appear in the map. But in this project, this would not be implemented due to lack of time. In Section 7.2. the navigation results obtained can be seen. Also the codes used are in Annex D.2.5. 42 6. CHARACTERIZATION WHEELCHAIR USER PERFORMANCE So far, the project has focused on the development of a wheelchair control platform, creating both automatic and adaptive controllers, which makes it usable by everyone and can therefore help people with cerebral palsy in their daily lives. That is why its application is not only limited to ASPACE centers, but is also a useful tool in facilities such as hospitals or geriatric centers, which are other places where users with motor disabilities or transient motor diseases can be found. At this point, considering that the wheelchair control platform is especially useful in health centers, it is interesting to incorporate a system for measuring physiological parameters. In this way, it would not only solve the mobility problems of users, but also would allow to: a. Supervise the person’s health from the wheelchair. [34] b. Supervise the person’s emotional state from the wheelchair. Although different adaptive controllers have been developed, user may have difficulties controlling the wheelchair and he may get nervous or stressed, so, based on physiological parameters it allows to detect if the user feels comfortable during navigation and to evaluate his adaptation over time. From here, based on the results found in the article ”Assessment of Emotional States Through Physiological Signals and Its Application in Music Therapy for Disabled People” by Andrea Valenzuela [35], which studies the biological effects of music on the human body by measuring the variability of physiological parameters, and the project ”Cardiovascular Scale” developed by the ISI Group from UPC [36], a hardware and a software have been adapted to be able to measure physiological signals. The basic measurement will be the electrocardiogram (ECG). 6.1. Acquisition system The first system used to measure physiological parameters has been the Biopac MP36 [37]. It is a lab system that includes the MP36 acquisition unit (hardware) with four amplification channels to capture data and the Biopac software to read and plot the physiologic signals on the computer. The channels of the MP36 are connected to electrodes created by the Department of Electronic Engineering from UPC, which are made of conductive fabric and are used as wristbands. This system can measure EMG, ECG, EEG, biofeedback, among others. 43 Figure 49: Left: Conductive ”wristbands”. Right: MP36 acquisition unit (hardware). Under: Use of the acquisition system to record an electrocardiogram. 6.2. Experimental results Once an acquisition system that allows to record physiological signals is had, what is wanted is to verify its correct operation by calculating parameters from these signals and see how they vary depending on the situation in which the user is. In this project, it has been worked with the ECG, which is a signal that represents the electrical activity of the heart and is measured from the potential difference detected by the electrodes. Figures 50 and 52 show an example of how the heartbeat occurs and what the electrocardiogram represents. Also, each step of the one-beat cardiac cycle is explained in [38](p.5). Figure 50: One-beat cardiac cycle with its corresponding electric pattern (ECG signal). The zones in purple indicate the presence of electrical activity at each step of the process [38] Figure 51: Example of an electrocardiogram signal recorded in the laboratory 44 This time, the parameter that interest to obtain from the electrocardiogram is the HR (in beats per minute). With the example in Figure 52, it can be seen that measured ECG signals have good quality and the different steps of the cardiac cycle can be identified with no problem. From here, a Matlab code that allows to calculated this parameter from the ECG signal has been created (see Annex D.3.1.). This algorithm first divides the vector of electric potentials into fragments equivalent to 5 seconds of sampling. Then, the Pan-Tompkins algorithm [42], which is used to detect complexes QRS in ECG, is applied to each of the subvectors. This algorithm applies a series of filters to highlight the frequency content of QRS complexes and removes the background noise; next, it squares the signal to amplify the QRS contribution; and finally, it applies adaptive thresholds to detect the peaks of the filtered signal. At this point, the number of R peaks in each interval and the time difference between them (RR interval) is saved in a vector. Finally means are compute and the number of R peaks for one minute (BPM) is calculated. Then, what has been done is to measure HR in a same subject in different situations consecutively to see his variability. In all cases 5 minutes electrocardiograms have been used, as it is considered the gold standard measurement. In them, the subject has been at rest or in a ”stressful” situation, being in the second case performing a Stroop test [43] or a mathematical test while recording its ECG. The results obtained have been the following ones: # Estate HR (BPM) Variation (BPM) 1 Repose 1 56 2 Stroop test (colors) 57.5 + 1.5 3 Mathematical test 1 61 + 3.5 4 Repose 2 52.75 - 8.25 5 Mathematical test 2 55 + 2.25 Table 19: ECG computed parameters for 5 minutes samples As can be observed in Table 19, when the subject goes from rest to a ”stressful” situation, his HR increases, and when the subject goes from a ”stressful” situation to rest, it decreases. Therefore, the results obtained are consistent with reality. However, having HR values every 5 minutes is not an efficient way to monitor users’ emotional state during navigation. That is why the HR has been recalculated but from a 30 second fragment of the 5-minute samples (Table 20). # Estate HR (BPM) Variation (BPM) 1 Repose 1 56 2 Stroop test (colors) 58 + 2 3 Mathematical test 1 61.5 + 3.5 4 Repose 2 52.5 - 9 5 Mathematical test 2 56 + 3.5 Table 20: ECG computed parameters for 30 seconds of the 5 minutes samples 45 The values obtained in this case are very close to the previous ones, which means that 30 seconds is enough time to be able to calculate the HR satisfactorily. Furthermore, to analyze the variability of the ECG signal in the different situations in which the user is found, Poincar´e Plots [44] have also been used. In the context of ECG signals, Poincar´e Plot is a graph of RR(n) on the x-axis versus RR(n+1) on the y-axis, being RR the time interval between two consecutive plots. The following Figure shows the Poincar´e Plot between measurements 4 and 5 and measurements 5 and 6. In this case they have been made for the five minute samples. Figure 52: Poincar´e Plots of five-minutes ECG measurements It is possible to observe how the different points of each measurement are grouped in a same region of the plot, being the points of measurement 5, where the subject was at rest and had the lowest heart rate, those that are located higher. This is consistent with the fact that the slower the heart rate the longer it spends between beats. In addition, how scattered the points are also gives information about the standard deviation of the RR intervals. In a Annex B.4.1. these plots can be seen for the 30 second samples. 6.3. Implementation Although the Biopac Lab system allows to measure physiological parameters without any problem, as can be seen in Figure 49, it is not convenient to implement it in a wheelchair, as it should load with the MP36 acquisition unit and users should wear the wristbands each time they board. That is why other hardware acquisition systems have been tested: a. BITalino. Hardware is based on the commercial BITalino board [45] used in [38]. This board, by means of sensors, allows to record a great number of physiological signals. It is a lightweight system that takes up little space but has the problem that it only has 10 bits of information, which is insufficient. Therefore it will not be used. 46 b. Acquisition system from the ”Cardiovascular Scale” project [36]. Hardware has been created by the ISI Group from UPC. It consist of a box that contains the corresponding devices inside and that acts as the MP36 acquisition unit. Apart from that, three sensor types can be used (Figures 53, 54 & 55): — Conductive wristbands. As in the Biopac Lab system conductive wristbands can be used. — Superficial sensors. Copper strips, that act as electrodes, are located in the armrests, where they have direct contact with hands’ skin. — Hidden sensors. Copper strips, that act as electrodes, are located under each leg in the seat, where they make measurements through the clothes. These sensors are less precise than superficial ones. In this way, the system is easy to implement to the wheelchair and there are different sensor alternatives, which don’t involve any effort for the user, who should not wear any extra items (superficial and hidden sensors). The system has 16 bits of information and allows to record physiological signals such as ECG, IPG, PPG, pulse oximetry, among others. In addition, depending on the parameter to be measured, one sensor or another must be used. For example, ECG and IPG can be measured with any of the three sensors, but PPG cannot be measured with hidden sensors. Hence, the measurement system developed in the ”Cardiovascular Scale” project is the option that best fits in this project. Here it can be seen a video of how it works. Figure 53: Left: Acquisition unit (hardware). Right: Copper strip electrodes placed in the wheelchair. Since the system can measure a large number of physiological signals, one of its applications in the field of cerebral palsy is its use as a ”polygraph”. People with cerebral palsy suffer from dysphagia, which is a disease that makes it difficult to swallow food because of the atrophy of the muscles in the neck. But is it known that when you’re a kid and you don’t like the food, you always look for excuses to avoid it, which in many cases makes it difficult for families or caregivers of children with cerebral palsy to know if when they do not want to eat it is really due to pain in swallowing. That is why controlling physiological parameters can help to detect if the person is really having problems or is trying to trick. 47 Therefore, in this chapter it has been designed an acquisition system for physiological signals that can be easily implemented in a wheelchair and has been shown to work correctly in calculating some ECG parameters. All this in order not only to offer mobility solutions to users but also to provide a system to control their health and emotional state. Figure 54: Capturing ECG signal with superficial and hidden sensors. Photograph taken at the laboratory. Figure 55: Capturing ECG signal with conductive wristbands. Photograph taken at ASPACE. It should be noted that the measures on people have passed the approval of the ethics committee to be able to carry them out and that the authorized consent of each person is had. 48 7. EXPERIMENTAL RESULTS AND EXPERIENCE IN ASPACE This chapter will cover the experimental results and the different tests performed in the laboratory and in the sessions at ASPACE. 7.1. ASPACE sessions The sessions have taken place in the Montju¨ıc center of ASPACE, where access has been had to the wheelchair to be able to do the necessary tests. From here, each of the sessions will be explained in order to present the results obtained, the problems that have arisen and the possible solutions to them. May 13th This was the first session, so the main goal was to get to know the ASPACE facilities, see the wheelchair that would be worked with and meet ` Angel Aguilar, who is the director of ASPACE. At ASPACE, since they only have one wheelchair, what they have done is build a platform with the same ECU and the same engines as the wheelchair. In this way, the tests can be performed also on this platform which gives more freedom in making possible changes in its structure. Note that as the control system developed is external to the wheelchair, it can be implemented without any problems on the platform or any other wheelchair. Figure 56: Left: Quantum Rehab Q4 wheelchair. Right: Electric platform. From here, as the adaptive control system was almost created what was done was to test in the platform if the control application and the three adaptive controllers were working correctly. 49 REFERENCES [1] I. T. Lakmal, K. L. A. Nuwan Perera, H. A. Harindu Y. Sarathchandra and C. Premachandra, ”SLAM-Based Autonomous Indoor Navigation System For Electric Wheelchairs,” 2020 International Conference on Image Processing and Robotics (ICIP), 2020, pp. 1-6, doi: 10.1109/ICIP48927.2020.9367336. https://ieeexplore.ieee.org/document/9367336 (accessed Feb. 18, 2022) [2] ”Intelligent system of a wheelchair with a Kinect camera and Arduino boar” at Flinders University, Australia. By Mazen Ahmed Shuwayaln and Dr Nasser Asgari. October 2019. https://vdocument.in/intelligent-system-of-a-wheelchair-with-a-kinect-camera- .html?page=1 (accessed Feb. 18, 2022) [3] “Design and Implementation of an Eye-Controlled Self-Driving Wheelchair”. By Hatem Al-Doais, Farouk A. K. Al-Fuhaidy, Ahmed T. Al-Oqabi, Esmail A. Qasabah, Ahmed A. Zabarah. https://escipub.com/ajsre-2020-09-1005/ (accessed March. 21, 2022) [4] Puanhvuan D, Khemmachotikun S, Wechakarn P, Wijarn B, Wongsawat Y. Navigationsynchronized multimodal control wheelchair from brain to alternative assistive technologies for persons with severe disabilities. Cogn Neurodyn. 2017 Apr;11(2):117-134. doi: 10.1007/s11571-017-9424-6. Epub 2017 Feb 15. PMID: 28348644; PMCID: PMC5350091. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5350091/ (accessed Feb. 23, 2022) [5] J. Kim et al., ”Assessment of the Tongue-Drive System Using a Computer, a Smartphone, and a Powered-Wheelchair by People With Tetraplegia,” in IEEE Transactions on Neural Systems and Rehabilitation Engineering, vol. 24, no. 1, pp. 68-78, Jan. 2016, doi: 10.1109/TNSRE.2015.2405072. https://ieeexplore.ieee.org/document/7050363 (accessed Feb. 23, 2022) [6] S. He et al., ”A P300-Based Threshold-Free Brain Switch and Its Application in Wheelchair Control,” in IEEE Transactions on Neural Systems and Rehabilitation Engineering, vol. 25, no. 6, pp. 715-725, June 2017, doi: 10.1109/TNSRE.2016.2591012. https://ieeexplore.ieee.org/document/7511656 (accessed Feb. 18, 2022) [7] Simpson RC, Levine SP. Voice control of a powered wheelchair. IEEE Trans Neural Syst Rehabil Eng. 2002 Jun;10(2):122-5. doi: 10.1109/TNSRE.2002.1031981. PMID: 12236450. 56 https://pubmed.ncbi.nlm.nih.gov/12236450/ (accessed March. 21, 2022) [8] “My Personal Robotic Companion”, Sung’s Blog. 28 September 2015. https://sungjik.wordpress.com/2015/09/28/my personal robotic companion/ (accessed March. 25, 2022) [9] “Robotics applied to disability”, Universitat Politecnica de Catalunya. By Maria Elisa Delgado Tejedor. https://upcommons.upc.edu/handle/2117/350350 (accessed Feb. 18, 2022) [10] Wikipedia contributors. ”Microcontroller.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 26 May. 2022. Web. 30 May. 2022. https://en.wikipedia.org/wiki/Microcontroller (accessed Mar. 25, 2022) [11] ”Arduino Due”, Arduino Store. http://store-usa.arduino.cc/products/arduino-due (accessed Mar. 27, 2022) [12] ”ESP32 NodeMCU M´odulo WLAN WiFi Development Board”, AZDelivery https://www.az-delivery.de/es/products/esp32-developmentboard (accessed Mar. 27, 2022) [13] ”What is the difference between adaptive wheelchair and active wheelchair?”, SORG. https://sorgrollstuhltechnik.de/wissen/what-is-the-difference-between-adaptive-wheelchair- and-active-wheelchair/ (accessed Mar. 28, 2022) [14] ”¿Qu´e es OpenCV?: ¡Descubre todo acerca de la visi´on artificial!”, Crehana. By Hugo Rodr´ıguez. 28 April 2021. https://www.crehana.com/blog/desarrollo-web/que-es-opencv/ (accessed Apr. 13, 2022) [15] ”¿Qu´e es ROS?”, Wiki ROS. http://wiki.ros.org/es/ROS/Introduccion (accessed Mar. 25, 2022) [16] ”An Introduction to Robot Operating System (ROS)”, All About Circuits. By Yahya Tawil. 26 June 2017. https://www.allaboutcircuits.com/technical-articles/an-introduction-to-robot-operating- system-ros/ (accessed Apr. 25, 2022) 57 [17] “Master Writer/Slave Reader”, Arduino. https://www.arduino.cc/en/Tutorial/LibraryExamples/MasterWriter (accessed Mar. 02, 2022) [18] “BlueDot BNO055 9-Axis IMU”, BlueDot. https://www.bluedot.space/products/bno055/ (accessed Feb. 27, 2022) [19] “USER MANUAL WT901C(RS485)”, WitMotion. https://drive.google.com/file/d/1tNTB4AVUVtpjYTLdlNrXe7A8Sw7tOyEh/view (accessed Feb. 27, 2022) [20] “Understanding Kalman Filters”, MathWorks. https://www.mathworks.com/videos/understanding-kalman-filters-part-1-why-use-kalman- filters–1485813028675.html (accessed Mar. 22, 2022) [21] Wikipedia contributors. ”Euler angles.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 23 Apr. 2022. Web. 30 May. 2022. https://en.wikipedia.org/wiki/Euler angles (accessed Mar. 12, 2022) [22] “Inertial sensor fusion”, MathWorks. https://www.mathworks.com/help/fusion/inertial-sensor-fusion.html (accessed Mar. 19, 2022) [23] “FILTERING OF IMU DATA USING KALMAN FILTER”, California State University, Sacramento. By Naveen Prabu Palanisamy. https://scholarworks.calstate.edu/downloads/dv13zt241 (accessed Apr. 20, 2022) [24] ”Incremental Photoelectric Rotary Encoder - 400P R SKU SEN0230”, Farnell. https://www.farnell.com/datasheets/3216191.pdf (accessed May. 18, 2022) [25] ”About Kobuki”, iClebo Kobuki http://kobuki.yujinrobot.com/about2/ (accessed Jun. 13, 2022) [26] ”What is a TurtleBot2?”, TurtleBot. https://www.turtlebot.com/turtlebot2/ (accessed Jun. 13, 2022) [27] Wikipedia contributors. ”TurtleBot.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 7 Jun. 2022. Web. 18 Jun. 2022. https://en.wikipedia.org/wiki/TurtleBot (accessed Jun. 15, 2022) 58 [28] ”Gmapping”, ROS Wiki. http://wiki.ros.org/gmapping (accessed Jun. 17, 2022) [29] ”Hector mapping”, ROS Wiki. http://wiki.ros.org/hector mapping (accessed Jun. 17, 2022) [30] ”RTAB-Map”, ROS Wiki. http://wiki.ros.org/rtabmap ros (accessed Jun. 17, 2022) [31] ”depthimage to laserscan”, ROS Wiki. http://wiki.ros.org/depthimage to laserscan (accessed Jun. 17, 2022) [32] ”move base”, ROS Wiki. http://wiki.ros.org/move base (accessed Jun. 18, 2022) [33] Wikipedia contributors. ”Particle filter.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 21 Jun. 2022. Web. 26 Jun. 2022. (accessed Jun. 19, 2022) [34] ”Smart wheelchair tracks user’s vitals, calls 911 in emergencies”, CNET-News. https://www.youtube.com/watch?v=fO8xNrxl8kg (accessed May. 13, 2022) [35] A. V. Ram´ırez, G. Hornero, D. Royo, A. Aguilar and O. Casas, ”Assessment of Emotional States Through Physiological Signals and Its Application in Music Therapy for Disabled People,” in IEEE Access, vol. 8, pp. 127659-127671, 2020, doi: 10.1109/ACCESS.2020.3008269. https://ieeexplore.ieee.org/document/9137201 (accessed May. 13, 2022) [36] ”Cardiovascular Scale”, Electronic Engineering Deparment from UPC. By Ramos Pallas Areny, Ramon Casanella Alonso, Jaime Oscar Casas Piedrafita, Gemma Hornero Oca˜na and Joan Gomez Clapers. https://futur.upc.edu/21331105 (accessed May. 14, 2022) [37] ”Sistema de pr´acticas para estudiantes MP36”, Bionic. https://www.bionic.es/marca/sistema-mp36/ (accessed May. 20, 2022) [38] ”Advanced Interfaces for the development of music-therapy in people with disabilities” by Andrea Valenzuela Ram´ırez. Instrumentation, Sensors and Interfeces Group from UPC. https://upcommons.upc.edu/handle/2117/167998 (accessed May. 14, 2022) 59 [39] Tsuji H, Venditti FJ Jr, Manders ES, Evans JC, Larson MG, Feldman CL, Levy D. Reduced heart rate variability and mortality risk in an elderly cohort. The Framingham Heart Study. Circulation. 1994 Aug;90(2):878-83. doi: 10.1161/01.cir.90.2.878. PMID: 8044959. https://pubmed.ncbi.nlm.nih.gov/8044959/ (accessed May. 21, 2022) [40] Mølgaard, H., Sørensen, K.E. Bjerregaard, P. Attenuated 24-h heart rate variability in apparently healthy subjects, subsequently suffering sudden cardiac death. Clinical Autonomic Research 1, 233–237 (1991). https://doi.org/10.1007/BF01824992 (accessed May. 21, 2022) [41] Task Force of the European Society of Cardiology the North American Society of Pacing Electrophysiology. Heart Rate Variability. Journal Article. 1996. Circulation. 1043-1065. 10.1161/01.CIR.93.5.1043 [doi] https://www.ahajournals.org/doi/10.1161/01.CIR.93.5.1043 (accessed May. 21, 2022) [42] Wikipedia contributors. ”Pan–Tompkins algorithm.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 8 Nov. 2021. Web. 6 Jun. 2022. https://en.wikipedia.org/wiki/Pan%E2%80%93Tompkins algorithm (accessed May. 27, 2022) [43] ”The Stroop Color and Word Test”, Frontiers in Psychology. By Federica Scarpina and Sofia Tagini. https://www.frontiersin.org/articles/10.3389/fpsyg.2017.00557/full (accessed May. 29, 2022) [44] Wikipedia contributors. ”Poincar´e plot.” Wikipedia, The Free Encyclopedia. Wikipedia, The Free Encyclopedia, 30 Oct. 2021. Web. 23 Jun. 2022. https://en.wikipedia.org/wiki/Poincar%C3%A9plot (accessedMay.30,2022)”BITalino(r)evolutionBoard”, Ultra −Lab. http ://ultra −lab.net/producto/bitalino −revolution −board −kit −bt/ (accessedMay.15,2022) 60 ANNEX A A.1. Inertial sensor quality measurements under antivibration static conditions BlueDot BNO055 IMU Figure 62: Linear acceleration measurement under antivibration static conditions Figure 63: Angular velocity measurement under antivibration static conditions 61 Figure 64: Linear acceleration histogram under antivibration static conditions Figure 65: Angular velocity histogram under antivibration static conditions Linearacceleration (m/s2)Mean Standard deviation X−axis 0.006 0.008 Y−axis 0.009 0.009 Z−axis −0.303 0.017 Table 21: Normal distribution parameters for linear acceleration errors Angular velocity (rad/s)Mean Standard deviation X−axis 0.002 0.135 Y−axis 0.001 0.165 Z−axis 0.008 0.066 Table 22: Normal distribution parameters for angular velocity errors 62 WitMotion WT901C485 IMU Figure 66: Linear acceleration measurement under antivibration static conditions Figure 67: Linear acceleration histogram under antivibration static conditions Linearacceleration (m/s2)Mean Standard deviation X−axis −0.067 0.003 Y−axis −0.008 0.009 Z−axis −0.008 0.004 Table 23: Normal distribution parameters for linear acceleration errors As in the case for normal static conditions, angular velocity measurements have been zero for all axis. 63 A.2. Kalman filters Kalman filter is an optimal estimation algorithm that predicts a parameter of interest in the presence of noisy measurements. It is very useful to estimate variables that can’t be measured directly but an indirect measurement is available; and also to find the best estimate of states by combining measurements from various sensors in the presence of noise. Its common applications include navigation, control systems and signal processing. [20] In order to estimate parameters of a system that cannot be measured directly an observation state is used. Being that other information can be obtained from the system, equations of the mathematical model that defines the real system can be found. But this is only an approximation, since the model is subjected to uncertainties. Obviously, if there were no uncertainties, the model found would be perfect and the estimated values would be identical to the real ones, but this is not the case in real life. Therefore, what is wanted is that for the variables that can be measured directly, the real measured value and the one estimated by the model are equal. Because this would mean that the mathematical model converges to the real system and that from this model can be estimated the real value of parameters that cannot be measured. To achieve this, a feedback control system with a state observer and a controller K is used. (See Figure 68.) Figure 68: Feedback control system with a state observer and a controller K In the control system urepresents the input, ythe output and xthe states to be estimated. Since it is wanted the estimated value to be equal to the real one, the error will be defined as: eobs =x−ˆx˙eobs = (A−KC)eobs The solution to this diferential equation is an exponencial, eobs(t) = e(A−KC)teobs(0) 64 what means that if (A−KC)<0, eobs converges to 0 in an infinite time. Also, KC term, which comes from the feedback loop, determines how faster the error vanishes. And here, the optimal way of choosing the gain K is performed through the use of Kalman filters. Now, it has to be considered that a noise measurement is present in the system. In Figure 69, wkrepresents a white noise with zero mean and covariance Qand vkrepresent a white noise with zero mean and covariance R. Since xestimation is uncertain due to noise here is where the Kalman filter is used, which combines two pieces of information (ˆx− kand yk) to calculate the best estimation (ˆxk). Figure 69: Optimal State Estimator First the filter starts with a prediction part, where the system model is used to calculate the a priori state estimate and the error covariance Pk, which comes from the process noise and propagation of the uncertain ˆxk−1. At the very start, the k-1 values for ˆxand Pkcome from their initial estimates. Secontly, the priori estimates calculated in the prediction step are updated to find the a posteriori estimates of the state and error covariance. Then, Kalman gain is calculated such that it minimizes the a posteriori error covariance. Finally, once the equations have been updated, in the next time step the a posteriori estimates are used to predict the new a priori estimates and the algorithm repeats itself, being recursive. (See Figure 70.) Figure 70: Kalman filter algorithm 65 Figure 80: Euler angles calculated from WitMotion WT901C485 data (using 6DOF) Figure 81: Euler angles calculated from WitMotion WT901C485 data (using 6DOF) after applying a low pass filter 72 B.3.2. Dynamic orientation estimation plots BlueDot BNO055 IMU Figure 82: Angular velocity from a rotational movement of the X-axis Figure 83: Acceleration from a rotational movement of the X-axis Figure 84: Angular velocity from a rotational movement of the Y-axis 73 Figure 85: Acceleration from a rotational movement of the Y-axis Figure 86: Angular velocity from a rotational movement of the Z-axis Figure 87: Acceleration from a rotational movement of the Z-axis 74 WitMotion WT901C485 IMU Figure 88: Angular velocity from a rotational movement of the X-axis Figure 89: Acceleration from a rotational movement of the X-axis Figure 90: Angular velocity from a rotational movement of the Y-axis 75 Figure 91: Acceleration from a rotational movement of the Y-axis Figure 92: Angular velocity from a rotational movement of the Z-axis Figure 93: Acceleration from a rotational movement of the Z-axis 76 B.3.3. Position estimation plots BlueDot BNO055 IMU Sampling 1 Figure 94: Position estimation in each one of the axis over time Sampling 2 Figure 95: Position estimation in each one of the axis over time 77 Sampling 3 Figure 96: Position estimation in each one of the axis over time Sampling 4 Figure 97: Position estimation in each one of the axis over time 78 WitMotion WT901C485 IMU Sampling 1 Figure 98: Position estimation in each one of the axis over time Sampling 2 Figure 99: Position estimation in each one of the axis over time 79 Sampling 3 Figure 100: Position estimation in each one of the axis over time 80 B.4.1. ECG Poincar´e Plots Figure 101: Poincar´e Plot of 30 s ECG measurements Figure 102: Poincar´e Plot of 30 s ECG measurements 81 196 di g i t a l W r it e (pinREVERSE, HIGH) ; 197 di g it al Wr it e (pinRIGHT , HIGH) ; 198 di g i t a l W r it e (pinLEFT , LOW) ; 199 } 200 e l s e i f ( ( j o y s t i c k x >502) && ( j o y s t i c k y <5) ) 201 { 202 di g i t a l W r it e (pinFORWARD, HIGH) ; 203 di g i t a l W r it e (pinREVERSE, HIGH) ; 204 di g i t a l W r it e (pinLEFT , HIGH) ; 205 di g it al Wr it e (pinRIGHT , LOW) ; 206 } 207 e l s e i f ( inputString . equals (”TOR”) | | inputSt ring . equals (”EYE ”) | | inputString . equals (”VOI”) ) 208 { 209 di g i t a l W r it e (pinFORWARD, HIGH) ; 210 di g i t a l W r it e (pinREVERSE, HIGH) ; 211 di g i t a l W r it e (pinLEFT , HIGH) ; 212 di g it al Wr it e (pinRIGHT ,HIGH) ; 213 break ; 214 } 215 e l s e 216 { 217 di g i t a l W r it e (pinFORWARD, HIGH) ; 218 di g i t a l W r it e (pinREVERSE, HIGH) ; 219 di g i t a l W r it e (pinLEFT , HIGH) ; 220 di g it al Wr it e (pinRIGHT , HIGH) ; 221 } 222 stringComplete=false ; 223 } 224 } 225 } 88 D.1.1.2. Wifi command reception code (AZDelivery ESP32) 1#include <Arduino . h> 2#d ef in e ESP32 3#include <WiFi . h> 4#d ef in e RF RECEIVER 13 5#d ef in e RELAY PIN 1 12 6#d ef in e RELAY PIN 2 14 7#d ef in e RELAY PIN 3 4 8#d ef in e RELAY PIN 4 16 9#incl u de ”fauxmoESP . h” 10 #include <RCSwitch .h> 11 #d ef in e SERIAL BAUDRATE 115200 12 #d ef in e WIFI SSID ”WIFI NAME” 13 #d ef in e WIFI PASS ”PASSWORD” 14 #d ef in e LAMP 1 ”Davant” 15 #d ef in e LAMP 2 ”Dreta” 16 #d e f i ne LAMP 3 ” Esquerra ” 17 #d ef in e LAMP 4 ” Enrere ” 18 fauxmoESP fauxmo ; 19 RCSwitch mySwitch = RCSwitch () ; 20 void wifiSetup ( ) { 21 WiFi . mode(WIFI STA) ; 22 S e r i a l . p r i n t f ( ” [ WIFI ] Connecting to %s ” , WIFI SSID) ; 23 WiFi . begin ( WIFI SSID , WIFI PASS) ; 24 while (WiFi . s t atus ( ) != WL CONNECTED) { 25 S e r i a l . print ( ” . ” ) ; 26 delay (100) ; } 27 S e r i a l . p r i n t l n ( ) ; 28 S e r i a l . p r i n t f ( ” [ WIFI ] STATION Mode , SSID : %s , IP address : %s \n” , WiFi . SSID () . c s t r () , WiFi . lo c al IP () . t o S t r i n g () . c s t r ( ) ) ;} 29 void setup () { 30 S e r i a l . begin (SERIAL BAUDRATE) ; 31 S e r i a l . p r i n t l n ( ) ; 32 wifiSetup () ; 33 pinMode (RELAY PIN 1 , OUTPUT) ; 34 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 35 pinMode (RELAY PIN 2 , OUTPUT) ; 36 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 37 pinMode (RELAY PIN 3 , OUTPUT) ; 38 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 89 39 pinMode (RELAY PIN 4 , OUTPUT) ; 40 di gi ta lWr it e (RELAY PIN 4 , LOW) ; 41 mySwitch . enableReceive (RF RECEIVER) ; 42 fauxmo . c r eate S erve r ( true ) ; 43 fauxmo . setPort (80) ; 44 fauxmo . enable ( true ) ; 45 fauxmo . addDevice (LAMP 1) ; 46 fauxmo . addDevice (LAMP 2) ; 47 fauxmo . addDevice (LAMP 3) ; 48 fauxmo . addDevice (LAMP 4) ; 49 fauxmo . onSetState ( [ ] ( unsigned char device id , const char ∗ device name , bool state , unsigned char value ) { 50 S e r i a l . p r i n t f ( ” [MAIN] Device #%d (%s ) s t a t e : %s value : %d\n” , device i d , device name , st a t e ? ”ON” : ”OFF” , value ) ; 51 i f ( ( strcmp ( device name , LAMP 1) == 0) ) { 52 S e r i a l . p r i n t l n (”RELAY 1 switched by Alexa ”) ; 53 i f ( st a t e ) { 54 di gi ta lWr it e (RELAY PIN 1 , HIGH) ; 55 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 56 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 57 di gi ta lWr it e (RELAY PIN 4 , LOW) ; 58 }e l s e { 59 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 60 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 61 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 62 di gi ta lWr it e (RELAY PIN 4 , LOW) ; } } 63 i f ( ( strcmp ( device name , LAMP 2) == 0) ) { 64 S e r i a l . p r i n t l n (”RELAY 2 switched by Alexa ”) ; 65 i f ( st a t e ) { 66 di gi ta lWr it e (RELAY PIN 2 , HIGH) ; 67 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 68 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 69 di gi ta lWr it e (RELAY PIN 4 , LOW) ; 70 }e l s e { 71 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 72 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 73 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 74 di gi ta lWr it e (RELAY PIN 4 , LOW) ;}} 75 i f ( ( strcmp ( device name , LAMP 3) == 0) ) { 76 S e r i a l . p r i n t l n (”RELAY 3 switched by Alexa ”) ; 90 77 i f ( st a t e ) { 78 di gi ta lWr it e (RELAY PIN 3 , HIGH) ; 79 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 80 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 81 di gi ta lWr it e (RELAY PIN 4 , LOW) ; 82 }e l s e { 83 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 84 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 85 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 86 di gi ta lWr it e (RELAY PIN 4 , LOW) ; } } 87 i f ( ( strcmp ( device name , LAMP 4) == 0) ) { 88 S e r i a l . p r i n t l n (”RELAY 4 switched by Alexa ”) ; 89 i f ( st a t e ) { 90 di gi ta lWr it e (RELAY PIN 4 , HIGH) ; 91 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 92 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 93 di gi ta lWr it e (RELAY PIN 3 , LOW) ; 94 }e l s e { 95 di gi ta lWr it e (RELAY PIN 4 , LOW) ; 96 di gi ta lWr it e (RELAY PIN 1 , LOW) ; 97 di gi ta lWr it e (RELAY PIN 2 , LOW) ; 98 di gi ta lWr it e (RELAY PIN 3 , LOW) ; } } }) ;} 99 void loop () { 100 fauxmo . handle () ; 101 s t a t i c unsigned long l a s t = m i l l i s () ; 102 i f ( m i l l i s () −l a s t >5000) { 103 l a s t = m i l l i s () ; 104 S e r i a l . p r i n t f ( ” [MAIN] Free heap : %d bytes\n” , ESP. getFreeHeap () ) ; } 105 i f ( mySwitch . a v a i l a b l e ( ) ) { 106 i f ( mySwitch . getReceivedValue ( ) ==6819768) { 107 di gi ta lW rit e (RELAY PIN 1 , ! digitalRead (RELAY PIN 1) ) ; } 108 i f ( mySwitch . getReceivedValue ( ) ==9463928) { 109 di gi ta lWr it e (RELAY PIN 2 , ! digitalRead (RELAY PIN 2) ) ; } 110 i f ( mySwitch . getReceivedValue ( ) ==9463928) { 111 di gi ta lWr it e (RELAY PIN 3 , ! digitalRead (RELAY PIN 3) ) ; } 112 i f ( mySwitch . getReceivedValue ( ) ==9463928) { 113 di gi ta lWr it e (RELAY PIN 4 , ! digitalRead (RELAY PIN 4) ) ; } 114 delay (600) ; 115 mySwitch . r e s e t Av a i l a b l e () ;}} 91 D.2.1. BNO055 sensor data capture Arduino code 1#include <Wire . h> 2#include <Adafruit Sensor . h> 3#include <Adafruit BNO055 . h> 4uint 1 6 t BNO055 SAMPLERATE DELAY MS = 10; 5uint 1 6 t PRINT DELAY MS = 500; 6uint 1 6 t printCount = 0; 7Adafruit BNO055 bno = Adafruit BNO055 (55 , 0x28 ) ; 8void setup ( void ) { 9S e r i a l . begin (115200) ; 10 i f ( ! bno . begin ( ) ) { 11 S e r i a l . print(”No BNO055 detected ”) ; 12 while (1) ; } 13 delay (1000) ;} 14 void loop ( void ) { 15 unsigned long t Star t = micros () ; 16 i f (printCount ∗BNO055 SAMPLERATE DELAY MS >= PRINT DELAY MS) { 17 imu : : Vector<3>e u l er = bno . getVector ( Adafruit BNO055 : :VECTOR EULER) ; 18 imu : : Vector<3>acc = bno . getVector ( Adafruit BNO055 : : VECTOR ACCELEROMETER) ; 19 imu : : Vector<3>l i n a c c = bno . getVector ( Adafruit BNO055 : : VECTOR LINEARACCEL) ; 20 imu : : Vector<3>gravity = bno . getVector ( Adafruit BNO055 : : VECTOR GRAVITY) ; 21 imu : : Vector<3>gyroscope= bno . getVector ( Adafruit BNO055 : : VECTOR GYROSCOPE) ; 22 imu : : Vector<3>magnetometer = bno . getVector ( Adafruit BNO055 : : VECTORMAGNETOMETER) ; 23 S e r i a l . p r i n t l n (”ANGLE SAMPLE”) ; 24 S e r i a l . print(”eX : ”) ; 25 S e r i a l . print( e u l er . x ( ) ,4) ; 26 S e r i a l . print(”eY : ”) ; 27 S e r i a l . print( e u l er . y ( ) ,4) ; 28 S e r i a l . print(” eZ : ”) ; 29 S e r i a l . p r i n t l n ( e u l e r . z ( ) , 4) ; 30 S e r i a l . print(”ACC X: ”) ; 31 S e r i a l . p r i n t l n ( acc . x ( ) ,4) ; 32 S e r i a l . print(”ACC Y: ”) ; 33 S e r i a l . p r i n t l n ( acc . y ( ) ,4) ; 92 34 S e r i a l . print(”ACC Z: ”) ; 35 S e r i a l . p r i n t l n ( acc . z ( ) , 4) ; 36 S e r i a l . print(” gravity X : ”) ; 37 S e r i a l . p r i n t l n ( g ra vi t y . x ( ) ,4 ) ; 38 S e r i a l . print(” gravity Y : ”) ; 39 S e r i a l . p r i n t l n ( g ra vi t y . y ( ) ,4 ) ; 40 S e r i a l . print(” gravity Z : ”) ; 41 S e r i a l . p r i n t l n ( g ra vi t y . z ( ) ,4 ) ; 42 S e r i a l . print(”LIN ACC X : ”) ; 43 S e r i a l . p r i n t l n ( l i n a c c . x ( ) ,4) ; 44 S e r i a l . print(”LIN ACC Y : ”) ; 45 S e r i a l . p r i n t l n ( l i n a c c . y ( ) ,4) ; 46 S e r i a l . print(”LIN ACC Z : ”) ; 47 S e r i a l . p r i n t l n ( l i n a c c . z ( ) , 4) ; 48 S e r i a l . print(” gyroscope X : ”) ; 49 S e r i a l . p r i n t l n ( gyroscope . x ( ) , 4) ; 50 S e r i a l . print(” gyroscope Y : ”) ; 51 S e r i a l . p r i n t l n ( gyroscope . y ( ) , 4) ; 52 S e r i a l . print(” gyroscope Z : ”) ; 53 S e r i a l . p r i n t l n ( gyroscope . z ( ) , 4) ; 54 S e r i a l . print(”magnetometer X : ”) ; 55 S e r i a l . p r i n t l n ( magnetometer . x ( ) ,4 ) ; 56 S e r i a l . print(”magnetometer Y : ”) ; 57 S e r i a l . p r i n t l n ( magnetometer . y ( ) ,4 ) ; 58 S e r i a l . print(” magnetometer Z : ”) ; 59 S e r i a l . p r i n t l n ( magnetometer . z ( ) ,4 ) ; 60 S e r i a l . p r i n t l n (” ”) ; 61 printCount = 0;} 62 e l s e { 63 printCount = printCount + 1;} 64 while (( micros () −tStart) <(BNO055 SAMPLERATE DELAY MS ∗1000) ) { 65 } 66 } 93 D.2.2. Orientation estimation Matlab code 1%% Captured data 2c l e a r a l l 3C11=readtable ( ’ vi b ra t ion s t a t i c WT901C485 . xlsx ’ ) ; 4D11=tab le2arra y (C11 ( : , [ 4 : 1 6 ] ) ) ; 5Ax11=D11 ( : , 1 ) ∗9.81; 6Ay11=D11 ( : , 2 ) ∗9.81; 7Az11=D11 ( : , 3 ) ∗9.81; 8Mx11=D11 ( : , 1 1 ) ; 9My11=D11 ( : , 1 2 ) ; 10 Mz11=D11 ( : , 1 3 ) ; 11 accelerometerReadings2 = [ Ax11 Ay11 Az11 ] ; 12 gyroscopeReadings2 = D11 ( : , 4 : 6 ) ; 13 magnetometerReadings2 = [ Mx11 My11 Mz11 ] ; 14 T11=[0.05:0.05:302.55] ’; 15 decim = 1; 16 %% Euler angles with 6DOF 17 fuse = i m u f i l t e r ( ’ SampleRate ’ , 0 .05 , ’DecimationFactor ’ , decim ) ; 18 q4 = fuse ( accelerometerReadings2 , gyroscopeReadings2 ) ; 19 f i g u r e ; 20 R4=eulerd ( q4 , ’ZYX ’ ,’ frame ’ ) ; 21 f i g u r e ; 22 hold on 23 pl ot (T11 ,R4 ( : , 3 ) , ’b ’ ) 24 pl ot (T11 ,R4 ( : , 2 ) , ’ r ’ ) 25 pl ot (T11 ,R4 ( : , 1 ) , ’ Color ’ ,’#EDB120 ’ ) 26 hold off 27 title(’ Orientation Estimate (WT901C485 6DOF) ’ ) 28 legend (’X Euler angle ’ ,’Y Euler angle ’ ,’Z Euler angle ’ ) 29 ylabel(’ Euler angles ( degrees ) ’ ) 30 xlabel(’Time ( s ) ’ ) 31 Fs =1/0.05; 32 t1 = [ 0 : 0 . 0 5 : 2 9 9 . 9 5 ] ; 33 r4=eulerd ( q4 , ’ZYX’ ,’ frame ’ ) ; 34 CON4= [ ] ; 35 f o r i =1:3 36 s4=r4 ( : , i ) ; 37 nfft=length ( s4 ) ; 38 n f f t 2 =2.ˆnextpow2( n f f t ) ; 39 fy=fft( s4 , n f f t 2 ) ; 94 40 fy=fy ( 1 : n f f t 2 /2) ; 41 x f f t=Fs . ∗( 0 : n f f t 2 /2−1)/ n f f t 2 ; 42 c u t o f f =0.2/Fs /2; 43 order =16; 44 h=f i r 1 ( order , c u t o f f ) ; 45 con4=conv ( s4 , h) ; 46 CON4=[CON4 con4 ] ; 47 end 48 figure ; 49 hold on 50 pl ot ( t1 , CON4(1:6000 , 3 ) , ’b ’ ) 51 pl ot ( t1 , CON4(1:6000 , 2 ) , ’ r ’ ) 52 pl ot ( t1 , CON4(1:6000 , 1 ) , ’ Color ’ ,’#EDB120 ’ ) 53 legend (’X Euler angle ’ ,’Y Euler angle ’ ,’Z Euler angle ’ ) 54 title(’ Orientation Estimate (WT901C485 6DOF) ’ ) 55 ylabel(’ Euler angles ( degrees ) ’ ) 56 xlabel(’Time ( s ) ’ ) 57 %% Euler angles with 9DOF 58 fuse = a h r s f i l t e r ( ’ SampleRate ’ , 0.05 , ’DecimationFactor ’ , decim ) ; 59 q3 = fuse ( accelerometerReadings2 , gyroscopeReadings2 , magnetometerReadings2) ; 60 R3=eulerd ( q3 , ’ZYX ’ ,’ frame ’ ) ; 61 f i g u r e ; 62 hold on 63 pl ot (T11 ,R3 ( : , 3 ) , ’b ’ ) 64 pl ot (T11 ,R3 ( : , 2 ) , ’ r ’ ) 65 pl ot (T11 ,R3 ( : , 1 ) , ’ Color ’ ,’#EDB120 ’ ) 66 hold off 67 title(’ Orientation Estimate (WT901C485 9DOF) ’ ) 68 legend (’X Euler angle ’ ,’Y Euler angle ’ ,’Z Euler angle ’ ) 69 ylabel(’ Euler angles ( degrees ) ’ ) 70 xlabel(’Time ( s ) ’ ) 71 Fs =1/0.05; 72 t1 = [ 0 : 0 . 0 5 : 2 9 9 . 9 5 ] ; 73 r3=eulerd ( q3 , ’ZYX’ ,’ frame ’ ) ; 74 CON3= [ ] ; 75 f o r i =1:3 76 s3=r3 ( : , i ) ; 77 nfft=length ( s3 ) ; 78 n f f t 2 =2.ˆnextpow2( n f f t ) ; 95 79 fy=fft( s3 , n f f t 2 ) ; 80 fy=fy ( 1 : n f f t 2 /2) ; 81 x f f t=Fs . ∗( 0 : n f f t 2 /2−1)/ n f f t 2 ; 82 c u t o f f =0.2/Fs /2; 83 order =16; 84 h=f i r 1 ( order , c u t o f f ) ; 85 con3=conv ( s3 , h) ; 86 CON3=[CON3 con3 ] ; 87 end 88 figure ; 89 hold on 90 pl ot ( t1 , CON3(1:6000 , 3 ) , ’b ’ ) 91 pl ot ( t1 , CON3(1:6000 , 2 ) , ’ r ’ ) 92 pl ot ( t1 , CON3(1:6000 , 1 ) , ’ Color ’ ,’#EDB120 ’ ) 93 title(’ Orientation Estimate (WT901C485 9DOF) ’ ) 94 legend (’X Euler angle ’ ,’Y Euler angle ’ ,’Z Euler angle ’ ) 95 ylabel(’ Euler angles ( degrees ) ’ ) 96 xlabel(’Time ( s ) ’ ) 96 D.2.3. Position estimation Matlab code 1%% Captured data 2c l e a r a l l 3C=read table ( ’ bno055static3 . xlsx ’ ) ; 4D=tab le2array (C( : , [ 1 0 : 1 2 ] ) ) ; 5Axx=D(1:5 7 0 ,1 ) ; 6mx=mean(Axx) ; 7Ax=Axx−mx∗ones (570 ,1) ; 8pAx=f i t d i s t (Ax, ’ Normal ’ ) ; 9Ayy=D(1:5 7 0 ,2 ) ; 10 my=mean(Ayy) ; 11 Ay=Ayy−my∗ones (570 ,1) ; 12 pAy=f i t d i s t (Ay, ’ Normal ’ ) ; 13 Azz=D( 1 :5 7 0 ,3) ; 14 mz=mean( Azz) ; 15 Az=Azz−mz∗ones (570 ,1) ; 16 pAz=f i t d i s t (Az , ’ Normal ’ ) ; 17 T=[0.53:0.53:302.1] ’; 18 %% P osition estimation X using Kalman f i l t e r 19 n=570; dt =0.53; 20 A=[1 dt dt ˆ2/2; 0 1 dt ; 0 0 1 ] ; B=0; 21 H=[1 0 0; 0 1 0; 0 0 1 ] ; u=0; 22 Q=[0; 0 ; 0 ] ; Q estimate=Q; 23 P=eye (3) ; Ex=eye(3) ; 24 R=[pAx. sigmaˆ2 0 0; 0 pAy . sigma ˆ2 0 ; 0 0 pAz . sigma ˆ 2 ] ; 25 x p = [ ] ; x v = [ ] ; x a = [ ] ; 26 xp estimate = [ ] ; xv estimate= [ ] ; xa es timate = [ ] ; 27 f o r i = 1: n 28 Q estimate curr = A ∗Q estimate + B ∗u ; 29 x p = [ x p ; Q estimate curr (1) ] ; 30 x v = [ x v ; Q estimate curr (2) ] ; 31 x a = [ x a ; Q estimate curr (3) ] ; 32 P = A ∗P∗A’ + Ex ; 33 K = P∗H’∗inv (H∗P∗H’+R) ; 34 y = [ Q estimate curr (1) ; Q estimate curr (2) ; Ax( i ) ] ; 35 Q estimate = Q estimate curr + K ∗(y −H∗Q estimate curr); 36 P = ( eye(3)−K∗H) ∗P; 37 xp estimate = [ xp estimate ; Q estimate (1) ] ; 38 xv estimate = [ xv estimate ; Q estimate (2) ] ; 39 xa estimate = [ xa estimate ; Q estimate (3) ] ; 97 67 double dtheta = 0 . 0 ; // change in o r i e n t a t i o n 68 double dt = 0 . 0 ; // time i n t e r v a l f o r a displacement 69 double vx = 0 . 0 ; // v e l o c i t y in the x d i r e c t i o n 70 double vy = 0 . 0 ; // v e l o c i t y in the y d i r e c t i o n 71 double dl = 0 . 0 ; // di stance t r a v e l l e d by l e f t wheel 72 double dr = 0 . 0 ; // di stance t r a v e l l e d by r ig ht wheel 73 double d is t = 0 . 0 ; // di st ance t r a v e l l e d by the centr e p o s i t i o n o f the wheels 74 double v = 0 . 0 ; // average v e l o c i t y o f the robot 75 double v ang = 0 . 0 ; // angular v e l o c i t y o f the robot 76 double new dtheta =0.0; 77 78 // Publisher chars 79 char b a s e l i n k [ ] = ”/ b a s e l i n k ” ; 80 char odom [ ] = ”/odom” ; 81 ros : : Rate r ( rate ) ; 82 83 //Node handle r e c e i v i n g i n f o 84 while(nh . ok () ) { 85 ros : : spinOnce ( ) ; 86 i f ( rece p t ion==1 | | re ce p ti on==2 ) { 87 88 // Compute important mechanics parameters of the system 89 current time = ros : : Time : : now () ; 90 dl=(two pi ∗R∗left wheel delta tick)/N; 91 dr=(two pi ∗R∗r i g h t w h e e l d e l t a t i c k ) /N; 92 d i s t =(dl+dr ) / 2; 93 //ROS INFO(”The l e f t w h e e l d e l t a t i c k : :[ % d ]” , left wheel delta tick); 94 dtheta=theta−thera pr e c ; 95 dt=( current time −l a s t t i m e ) . toSec ( ) ; 96 97 // compute odometric poses 98 x+=d i s t ∗cos ( new dtheta+(dtheta / 2 . 0 ) ) ; 99 y+=d i s t ∗si n ( new dtheta+(dtheta / 2 .0 ) ) ; 100 new dtheta+=dtheta ; 101 102 // compute odometric instantaneous v e l o c i t i e s 103 v=d i s t /dt ; 104 v ang=dtheta /dt ; 104 105 geometry msgs : : Quaternion odom quat = t f : : createQuaternionMsgFromYaw ( new dtheta ) ; 106 geometry msgs : : TransformStamped t ; 107 108 /∗Publish messages ∗/ 109 // TF topic 110 t . header . frame id = odom ; 111 t . c h i l d f r a m e i d = b a s e l i n k ; 112 t . transform . t r a n s l a t i o n . x = x ; 113 t . transform . t r a n s l a t i o n . y = y ; 114 t . transform . t r a n s l a t i o n . z = 0 . 0 ; 115 t . transform . rot a ti on = odom quat ; 116 t . header . stamp = current time ; 117 broadcaster . sendTransform ( t ) ; 118 119 // Odometry to pic 120 nav msgs : : Odometry odom msg ; 121 odom msg . header . stamp = current time ; 122 odom msg . header . frame id = odom ; 123 odom msg . pose . pose . p o s i t i o n . x = x ; 124 odom msg . pose . pose . p o s i t i o n . y = y ; 125 odom msg . pose . pose . p o s i t i o n . z = 0 . 0 ; 126 odom msg . pose . pose . o r i e n t a t i o n = odom quat ; 127 odom msg . c h i l d f r a m e i d = b a s e l i n k ; 128 129 // We should update the tw i st of the odometry 130 odom msg . twist . twist . l i n e a r . x = v ; 131 odom msg . twist . twist . l i n e a r . y = 0 . 0 ; 132 odom msg . twist . twist . angular . z = v ang ; 133 odometry publisher . publish ( odom msg ) ; 134 thera prec=theta ; 135 l a s t t i m e=c ur re nt t im e ; 136 recept i o n =0; 137 r . sl e e p () ; 138 } 139 } 140 } 105 D.2.5.2. ECU control Arduino code 1/∗ROS ∗/ 2#i f (ARDUINO >= 100) 3#include <Arduino . h> 4#else 5#include <WProgram . h> 6#e n di f 7#include <ros . h> 8#include <geometry msgs /Vector3Stamped . h> 9#include <geometry msgs /Twist . h> 10 #include <ros / time . h> 11 //#include ” r obot sp e c s . h” 12 /∗Arduino PINS ∗/ 13 #d ef in e encodPinONOFF 1 14 #d ef in e encodPinFORWARD 2 15 #d ef in e encodPinREVERSE 3 16 #d ef in e encodPinTURNLEFT 4 17 #d ef in e encodPinTURNRIGHT 5 18 #d ef in e LOOPTIME 100 19 #define sign (x ) ( x >0) −( x <0) 20 21 /∗Variable i n i t i a l i z a t i o n ∗/ 22 ros : : NodeHandle nh ; // Handles publi s hing and sub s cri b i ng to t o pi c s 23 // Timing 24 unsigned long l a s t M i l l i = 0; 25 unsigned long l a stMill i P ub = 0; 26 #d ef in e L 1 // d i s t a n c e between wheels 27 // V e l o c i t i e s ( actu al and requ ire d ) each wheel 28 double v e l r i g h t = 0; 29 double v e l l e f t = 0; 30 31 /∗ROS message handling ∗/ 32 void handle cmd ( const geometry msgs : : Twist& cmd msg ) { 33 double vx = cmd msg . l i n e a r . x ; 34 double vz = cmd msg . angular . z ; 35 v e l r i g h t = vx+(vz∗L/2) ; 36 v e l l e f t = vx−(vz∗L/2) ; } 37 ro s : : Subscriber <geometry msgs :: Twist>sub (” cmd vel ” , handle cmd ) ; 38 geometry msgs : : Vector3Stamped vel msg ; 39 ros : : Pu blish er v e l p u b l i s h e r (” v el ” , &vel msg ) ; 106 40 ros : : Time current time ; 41 ro s : : Time l a s t t i m e ; 42 43 void setup () { 44 // Init variables 45 v e l r i g h t = 0 . 0 ; 46 v e l l e f t = 0 . 0 ; 47 // I n i t Node Handle 48 nh . initNode ( ) ; 49 nh . getHardware ( )−>setBaud (57600) ; 50 nh . subscribe( sub ) ; // Subscribes to geometry msgs : : Twist topi c } 51 52 void loop () { 53 nh . spinOnce () ; // Asks ROS to process the upcoming messages 54 unsigned long time = m i l l i s () ; // Time sin c e machine s tar t ed 55 i f ( time −lastMilli >= LOOPTIME) { 56 // Set new command to wheels : 57 // Forward , re ve rs e or stop 58 i f ( ( v e l r i g h t == v e l l e f t ) && ( v e l r i g h t >0) ) { d e s a c t i v a t e p i n s ( ) ; d i g it a l W ri t e (encodPinFORWARD, HIGH) ; } 59 e l s e i f ( ( v e l r i g h t == v e l l e f t ) && ( v e l r i g h t <0) ) { d e s a c t i v a t e p i n s ( ) ; d i gi t a l Wr i t e (encodPinREVERSE , HIGH) ; } 60 e l s e i f ( ( v e l r i g h t == v e l l e f t ) && ( v e l r i g h t == 0) ) { d e s a c t i v a t e p i n s ( ) ; di g i t al W r i te (encodPinONOFF , LOW) ; } 61 // Turn 62 e l s e i f ( ( v e l r i g h t != v e l l e f t ) && ( v e l r i g h t <vel left) ) { d e s a c t i v a t e p i n s ( ) ; di g i t al W r i te (encodPinTURNRIGHT , HIGH) ; } 63 e l s e i f ( ( v e l r i g h t != v e l l e f t ) && ( v e l r i g h t >vel left) ) { d e s a c t i v a t e p i n s ( ) ; di g i t al W r i te (encodPinTURNLEFT , HIGH) ; } 64 l a s t M i l l i = time ; } 65 i f ( time −lastMilliPub >= LOOPTIME) { 66 lastMilliPub = time; } } 67 68 void d e s a c t i v a t e p i n s ( ) { 69 di g i t a l W r it e (encodPinFORWARD, LOW) ; 70 di g i t a l W r it e (encodPinREVERSE , LOW) ; 71 di g i t a l W r it e (encodPinONOFF , LOW) ; 72 di g i t a l W r it e (encodPinTURNRIGHT, LOW) ; 73 d ig i t al W ri t e (encodPinTURNLEFT , LOW) ; } 107 D.2.5.3. Odometry sensors data Arduino code 1#include <Wire . h> 2#include <Adafruit Sensor . h> 3#include <Adafruit BNO055 . h> 4Adafruit BNO055 bno = Adafruit BNO055 (55 , 0x28 ) ; 5#include <ros . h> 6#include <std msgs / Int16 . h> 7#include <std msgs / Float64 . h> 8#d e f i ne f a c t 0.0174533 // degree to ra di an s 9 10 // Handles startup and shutdown of ROS 11 ros : : NodeHandle nh ; 12 13 // Encoder output to Arduino I nt er ru pt pin . Tracks the t i c k count . 14 #d ef in e ENC IN LEFT A 3 15 #d ef in e ENC IN RIGHT A 2 16 17 // Other encoder output to Arduino to keep tra ck o f wheel d i r e c t i o n 18 // Tracks the d i r e c t i o n of r ot a ti o n . 19 #d ef in e ENC IN LEFT B 11 20 #d ef in e ENC IN RIGHT B 8 21 22 // True = Forward ; False = Reverse 23 boolean D i r e c t i o n l e f t = true ; 24 boolean D i r e c t i o n r i g h t = tr ue ; 25 26 // Minumum and maximum values 16−bit integers 27 const i nt encoder minimum = −32768; 28 const i nt encoder maximum = 32767; 29 30 // Keep track of the change in number of wheel t i c k s 31 std msgs : : Int16 r i g h t w h e e l d e l t a t i c k ; 32 ros : : Publisher rightPub (” r i g h t t i c k s ” , &r i g h t w h e e l d e l t a t i c k ) ; 33 std msgs : : Int16 l e f t w h e e l d e l t a t i c k ; 34 ros : : Publisher leftPub (” l e f t t i c k s ” , &l e f t w h e e l d e l t a t i c k ) ; 35 36 // Orientation 37 std msgs : : Float64 orient ; 38 ro s : : P ub li sh er orientPub (” o r i e n t a t i o n ” , &orient) ; 39 108 40 // 100ms i n t e r v a l measurements 41 const i nt i n t e r v a l = 100; 42 long p r e v i o u s M i l l i s = 0 ; 43 long c u r r e n t M i l l i s = 0 ; 44 45 //Get the number o f t i c k s with time 46 int right wheel tick count ; 47 in t l e f t w h e e l t i c k c o u n t ; 48 int previous right wheel tick count=0; 49 i nt p r e v i o u s l e f t w h e e l t i c k c o u n t =0; 50 51 // Increment the number of t i c k s 52 void r i g h t w h e e l t i c k ( ) { 53 // Read ri g h t wheel encoder value 54 in t value = digitalRead (ENC IN RIGHT B) ; 55 i f ( value == LOW) { 56 D i r e c t i o n r i g h t = f a l s e ; // Reverse 57 } 58 e l s e { 59 D i r e c t i o n r i g h t = true ; // Forward 60 } 61 i f (Direction right) { 62 i f ( r i g h t w h e e l t i c k c o u n t == encoder maximum ) { 63 r i g h t w h e e l t i c k c o u n t = encoder minimum ; 64 } 65 e l s e { 66 r i g h t w h e e l t i c k c o u n t ++; 67 } 68 } 69 e l s e { 70 i f ( r i g h t w h e e l t i c k c o u n t == encoder minimum ) { 71 r i g h t w h e e l t i c k c o u n t = encoder maximum ; 72 } 73 e l s e { 74 right wheel tick count−−; 75 } 76 } 77 } 78 79 // Increment the number of t i c k s 109 80 void l e f t w h e e l t i c k () { 81 // Read l e f t wheel encoder value 82 in t value = digitalRead (ENC IN LEFT B) ; 83 i f ( value == LOW) {//Keep in mind that when the ri gh t wheel ro t a t e s clo c k wise the l e f t ro ta t e s ant ic lo ck wi se and vice −versa 84 D i r e c t i o n l e f t = true ; // Reverse 85 } 86 e l s e { 87 D i r e c t i o n l e f t = f a l s e ; // Forward 88 } 89 i f (Direction left) { 90 i f ( l e f t w h e e l t i c k c o u n t == encoder maximum ) { 91 l e f t w h e e l t i c k c o u n t = encoder minimum ; 92 } 93 e l s e { 94 l e f t w h e e l t i c k c o u n t ++; 95 } 96 } 97 e l s e { 98 i f ( l e f t w h e e l t i c k c o u n t == encoder minimum ) { 99 l e f t w h e e l t i c k c o u n t = encoder maximum ; 100 } 101 e l s e { 102 l e f t w h e e l t i c k c o u n t −−; 103 } 104 } 105 } 106 107 void setup () { 108 // Set pin s t a t e s of the encoder 109 pinMode (ENC IN LEFT A , INPUT PULLUP) ; 110 pinMode (ENC IN LEFT B , INPUT) ; 111 pinMode (ENC IN RIGHT A , INPUT PULLUP) ; 112 pinMode (ENC IN RIGHT B , INPUT) ; 113 // Every time the pin goes high , t h i s i s a t i c k 114 att a c h I nterrupt ( digital P i n ToInterrup t (ENC IN LEFT A) , l e f t w h e e l t i c k , RISING) ; 115 att a c h I nterrupt ( digital P i n ToInterrup t (ENC IN RIGHT A) , ri g ht wh e e l ti c k , RISING) ; 116 // ROS Setup 110 117 nh . getHardware ( )−>setBaud (115200) ; 118 nh . initNode ( ) ; 119 nh . a d ve r t i s e ( rightPub ) ; 120 nh . a d ve r t i s e ( leftPub ) ; 121 nh . a dv e r t is e ( orientPub ) ; 122 i f ( ! bno . begin () ) 123 { 124 while (1) ; 125 } 126 delay (1000) ; 127 } 128 129 void loop () { 130 // Record the time 131 c u r r e n t M i l l i s = m i l l i s ( ) ; 132 imu : : Vector<3>e u l er = bno . getVector ( Adafruit BNO055 : :VECTOR EULER ) ; 133 // I f 100ms have passed , c a l c u l a t e and pub li sh the change in t i c k s 134 i f ( c u r r e n t M i l l i s −previousMillis >i n t e r v a l ) { 135 p r e v i o u s M i l l i s = c u r r e n t M i l l i s ; 136 r i g h t w h e e l d e l t a t i c k . data= r ig ht w he el t ic k co un t − previous right wheel tick count ; 137 l e f t w h e e l d e l t a t i c k . data= l ef t w he el t ic k c ou n t − previous left wheel tick count ; 138 orient . data=f a c t ∗e ul e r . x () ; 139 i f ( r i g h t w h e e l t i c k c o u n t != p r e v i o u s r i g h t w h e e l t i c k c o u n t | | l e f t w h e e l t i c k c o u n t != p r e v i o u s l e f t w h e e l t i c k c o u n t ) // i f we don ’ t have new t i c k s we don ’ t send the information 140 { 141 p r e v i o u s r i g h t w h e e l t i c k c o u n t=r i g h t w h e e l t i c k c o u n t ; // For the next i t e r a t i o n we save the a ct ua l value o f the t i c k in order to compute the change in the next i t e r a t i o n 142 p r e v i o u s l e f t w h e e l t i c k c o u n t=l e f t w h e e l t i c k c o u n t ; 143 // Sending information to ROS 144 orientPub . publish ( &orient) ; 145 rightPub . publish ( &r i g h t w h e e l d e l t a t i c k ) ; 146 leftPub . publish ( &l e f t w h e e l d e l t a t i c k ) ; 147 } } 148 nh . spinOnce () ; 149 } 111 D.3.1. ECG parameters Matlab code 1function [ T bpm ,T NP, T RRmean,T SDNN]= v a r i a b i l i t y (ECG, Rate ) 2% EGC v ec t or s f o r each per io d 3ECG vec = ECG(1:300∗Rate ) ; 4% Parameters : 5i i = 1; n = 1; N = Rate ∗5; 6prop = Rate /1000; 7% Acquisit ion time 8t = 300; 9% Empty ve c t o rs : 10 Peaks= [ ] ; % Rwave detections 11 RR vec = [ ] ; % Time between c o nsecuti ve R waves 12 while N−1<length (ECG vec ) 13 ECG= ECG vec (n :N) ; 14 tt= [ n :N] . / Rate ; 15 %ECG −Analysis PanTompkin 16 [ qrs amp raw , q rs i raw , delay1 ]=pan tompkin (ECG, Rate , 0 ) ; 17 % R WAVES 18 Peaks = [ Peaks , tt ( q r s i r a w ) ] ; 19 n = N; N = N + 10000; 20 i i = i i + 1; 21 end 22 % Number o f peaks in each i n t e r v a l 23 NP mean = 10∗length ( Peaks ) . /3 0 0 ; 24 % SDNN ( Standar deviation N−N i n t e r v a l ) 25 SDNN1 = std (d i f f (Peaks rest1)); 26 % RR mean 27 RR = diff( Peaks ) ; RR mean = mean(RR) ; 28 % BPM COMPUTATION 29 bpm = 30∗60∗NP mean/ t ; 30 % Values 31 T bpm = t a ble (bpm, ’VariableNames ’ ,{’BPM’ })%Beats per minute 32 T NP = table (NP mean , ’VariableNames ’ ,{’NP’ })% Number of peaks in each i n t e r v a l (10 s ) 33 T RRmean = ta ble (RR mean , ’VariableNames ’ ,{’RRmean ’ })% R peak to R peak 34 T SDNN = t a b l e (SDNN1, ’VariableNames ’ ,{’SDNNRest1 ’ }) ; %Standard Deviation of NN( or RR) i n t e r v a l s 35 end 112