Choosing the optimal gear when biking can be challenging, especially for beginner cyclists. Many factors can impact the selection of a gear including the incline, the terrain, the bike’s construction, and the cyclist’s level of fatigue. General biking wisdom suggests choosing a gear to maintain a pedaling cadence of 60-80 revolutions per minute. Improperly choosing a gear and cycling outside of this cadence range can lead to less efficient pedaling, a loss of performance, and a less enjoyable cycling experience.
As a part of the Design of Microprocessor-based Mechanical Systems course, our team of three developed an automatic gear shifter and associated graphical user interface (GUI) that allows a cyclist to effortlessly maintain an optimal pedaling cadence regardless of the incline or terrain. The software of the project had to include: 1) real-time programming, 2) multi-tasking, and 3) an interactive GUI.
The SmartCycle system integrates the ground speed, measured from a reed switch counting the revolutions of the back wheel, and the cyclist’s pedaling cadence, measured from an IMU, to “smartly” shift gearing and maximize performance. The system physically shifts the gears of the bike by precisely tightening or loosening the shifter cable via a real-time, PD controlled, worm drive motor and encoder.
In automatic shifting mode, the system aims to keep the cyclist between their maximum and minimum cadence at all times (between 60 and 80 RPM) by shifting gears as needed. The user also has the option to manually shift gears by pressing upshift and downshift buttons. The current and target gear are displayed on a handlebar LED strip. Additionally, the GUI for SmartCycle provides the user a visual display of their riding performance as well as access to tuning parameters to better optimize their ride.
SmartCycle uses the states of ASLEEP, STOPPED, and BIKING to manage all of these operations safely. Specifically, the states are used to control when automatic shifting can be engaged. For example, when the bike is STOPPED or ASLEEP, SmartCycle should not be shifting gears.
State Diagram
SmartCycle consists of a primary and secondary ESP32 to handle all of the embedded software. The primary ESP32 handles the states, the gear shifting logic, the real-time motor controller, ground speed measurements, communication with the GUI and secondary ESP32, the control of the manual shift buttons, and illuminating of the LED indicator strip. The secondary ESP32 utilizes an onboard IMU to output the rider’s cadence. SmartCycle was developed using PlatformIO in VSCode.
Our system runs multiple tasks simultaneously through a combination of interrupts and timed routines. On the gear shifting side, SmartCycle completes tasks dealing with the controller ISR to update the positioning of the motor, read off the encoder’s position, and the GPIO interrupts with the upshift/downshift buttons. At the same time, the system uses interrupts to ensure that the cadence measurements via ESP-NOW are received and that ground speed measurements are recorded via the reed switch’s activation. The efficient, concurrent juggling of the gear shifting tasks and sensor data is critical to ensure effective and safe biking operation.
On top of all that, while SmartCycle is processing all of its functioning tasks, the system is also using protobuffers and other protocols to publish telemetry data wirelessly to the GUI and receive updated tuning parameters from the rider all in the background.
In addition to helping architect the system/states, develop the gear shifting & communication logic, implementing real-time and multi-tasking, and troubleshooting software, I also spearheaded the GUI development and cadence integration.
The GUI is displayed on a laptop that is wirelessly communicating with the primary ESP32, specifically through a web socket server connection. The GUI displays the rider’s telemetry metrics and tuning parameters are displayed; two dials display the live ground speed and cadence of the rider, vertical sliders display the current and target gear, and the horizontal sliders in the right column display the various tuning parameters. The tuning parameters allow the rider to: 1) adjust the corresponding encoder value for each gear to ensure proper shifting and 2) set their desired cadence that SmartCycle should gear shift in accordance with. The GUI is hosted on a python program, which was built using Tkinter libraries.
Smart Cycle Monitor
In addition to the current and target gears being displayed on the GUI, LED strips are also illuminated; green indicates the current gear, while blue indicates the target gear.
Gear Indicators
The secondary or cadence ESP32 was responsible for publishing the cadence of the rider. As the rider pedals, this ESP32 records measurements of the angular velocity through the IMU. Then the equivalent RPM value is sent to the primary ESP32 through the ESP-NOW protocol, which essentially establishes the ESP32 as a Wifi station to specifically communicate with the MAC Address of the other ESP32. To smooth the measurements and control the sampling rate, a periodic ESP timer (interrupt) is used to send a smoothed RPM value every 100 ms.
In the end, we successfully completed a fully functional tabletop demo of our prototype. With Finals approaching, we decided to postpone physically integrating everything onto a bike. Our next steps will include performance and edge-case testing.