# Data-Driven Safe Deliveries: The Synergy of IoT and Machine Learning in Shared Mobility
## 5 Results and Discussion
### Edge Monitoring  
The edge monitoring process was completed by reading data from various sensors, including the ultrasonic sensor, acceleration and gyroscope sensors, impact sensor, and camera, at the physical layer. The deployed program on the edge computing unit facilitated real-time warnings to be generated based on the sensor data. To detect nearby objects, the ultrasonic sensor measured distances, and if the measured distance was less than 2 m, indicating the presence of a nearby object, the edge computing unit immediately triggered a warning that was sent to the driver's smartphone. For the acceleration and gyroscope readings, the program calculated the root mean square value of the \(x\)-axis accelerometer jerk, \(y\)-axis accelerometer jerk, \(z\)-axis accelerometer jerk as well as the root mean square value of the \(x\)-axis gyroscope jerk, \(y\)-axis gyroscope jerk, and \(z\)-axis gyroscope jerk. To calculate the jerk from accelerometer readings (in m/s\({}^{2}\)) for each axis, the third derivative of the acceleration values in m/s\({}^{2}\) over time was computed. Similarly, to calculate the jerk from gyroscope readings (in degrees/second) for each axis, the angular velocity values for each axis were integrated over time to obtain linear acceleration, and then, the third derivative of this linear acceleration over time was calculated. These calculations were performed every 500 ms on arrays containing 20 readings from the accelerometer and gyroscope. Furthermore, the program maintained a rolling average of the root mean square values of the gyroscope and accelerometer jerk values. When any newly calculated jerk value deviated by 15% from the rolling average, a warning would be triggered and sent to the driver's mobile phone, alerting them to a possible risky maneuver. The 15% deviation threshold was determined through extensive trials on the bike to identify the percentage difference value that effectively captured irregular behavior. In the event of impact sensor detection, the program on the edge computing unit would be immediately interrupted, triggering an accident response from the mobile application. The mobile application provided the rider with a 5 s window and prompted them to confirm or deny the occurrence of the accident (in case of a faulty reading). If the driver does not respond during the 5 s window, the system automatically sets the accident flag as true. If the accident flag is set to true, the application automatically calls the driver's emergency contacts, providing them with the location coordinates captured from the phone's GPS capability. Throughout the ride, the video camera recorded the journey from start to finish, and in the event of an accident, it recorded an additional two minutes of footage. A risk level was calculated by dividing the number of warnings triggered during the ride's duration in minutes, which was multiplied by 120 to account for the program's 500 ms warning checks, resulting in a maximum of 120 checks per minute. The calculated value was then converted to a scale of 0 to 100. If an accident was triggered during the ride, the risk level was automatically set to 100. The risky instances (the 20 sensor readings generated before each warning), along with the calculated risk level, ride's video recording, and start and end times, were aggregated and sent to the application servers for further analysis and storage. The edge monitoring process involved the testing of both hardware and software components. For hardware testing, the impact sensor was subjected to different force intensities, and the results showed that it detected impacts accurately in various scenarios. The ultrasonic sensor was tested for its range of distance measurement, and it effectively detected nearby objects during the rides. The accelerometer and gyroscope sensor exhibited sensitivity to bike movements and rotations, accurately capturing changes in acceleration and angular velocities.