final report rev3 - gatech.eduume.gatech.edu/mechatronics_lab/projects/fall08/group3/... · 2009....

29
ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic Bike Transmission 4/18/09 Razid Ahmad Brandon Borm Todd Sifleet

Upload: others

Post on 01-Aug-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

ME 8843 - Advanced Mechatronics

Dr. Ume Spring 2009

Final Report - Automatic Bike Transmission

4/18/09

Razid Ahmad Brandon Borm

Todd Sifleet

Page 2: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

1

Introduction: ........................................................................................................................ 2 Introduction: ........................................................................................................................ 2 Vision: ................................................................................................................................. 2 System Analysis: ................................................................................................................. 2

Mechanical: ..................................................................................................................... 2 Gear Actuation: ........................................................................................................... 2 System Integration: ..................................................................................................... 3

Electrical: ........................................................................................................................ 3 Sensors: ....................................................................................................................... 3 Power Supply: ............................................................................................................. 4

Implementation: .................................................................................................................. 4 Mechanical: ..................................................................................................................... 4

Gear Actuation: ........................................................................................................... 4 User Interface: ............................................................................................................. 5 Main Enclosure: .......................................................................................................... 7 Sensor Mounting: ........................................................................................................ 8 Battery Mounting: ..................................................................................................... 10

Electrical: ...................................................................................................................... 10 Sensors: ..................................................................................................................... 10 Power Supply: ........................................................................................................... 11 Interconnects: ............................................................................................................ 12 User Interface: ........................................................................................................... 12

Software: ....................................................................................................................... 13 Back End Code: ........................................................................................................ 13 Front End Code: ........................................................................................................ 14

Hardware: ...................................................................................................................... 15 Future Work: ..................................................................................................................... 15 Conclusion: ....................................................................................................................... 16 References: ........................................................................................................................ 16 Appendix A: ...................................................................................................................... 17 Appendix B: ...................................................................................................................... 18 Appendix C: ...................................................................................................................... 19

Page 3: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

2

Introduction: The goal of this project was to create an automatic transmission for a common

bicycle. This system must shift the bicycle smoothly through the gears on the bicycle. In order to determine when to properly shift the bicycle, the transmission must incorporate input measurements of torque applied by the cyclist, pedaling rate, and bike speed. Also, a manual mode should be available so that the rider can have full control over gear shifting. An effective user interface must also be incorporated into the bicycle so that the rider can see his/her speed, current gear, and change between manual and automatic mode. The user interface also functions as an odometer that measures current speed, average speed, and distance traveled.

Vision: At the beginning of the semester we formed a vision of what we were trying to

create, this vision contained multiple features/functions:

Mechanical Shifting: The most fundamental function of the system is its ability to effectively shift from gear to gear. From the beginning we felt that the standard bike derailleur system could be actuated by a high torque motor: stepper, servo, DC motor (high gear ratio). Originally one of our main design goals was to have a “self-locking” system that required no energy to maintain its position. User Interface: We saw the device being easily controlled by the rider, this includes a visual interface (LCD display) and buttons for user input. The bike would allow the rider to override the automatic controller and shift the gears manually. Lastly since we were implementing an LCD display we wanted to utilize it to display relevant information: speed, average speed, and distance. Sensors: In order to implement an intelligent controller it was important to measure real time data from the bicycle. This data is important for the controller to be able to measure the cyclist’s riding effort. To accomplish this we decided to focus on measuring rider speed, rider acceleration, and angle of inclination. Controller: Our ultimate goal was to create a device that could intelligently shift a bicycle and create a more enjoyable riding experience. This required the implementation of an effective controller, which is a non-trivial task. We envisioned a controller that could sense how much effort the cyclist was exerting and would shift accordingly. Furthermore, by combining effort and pedal rate, we sought to create a consistent and effective controller.

System Analysis:

Mechanical:

Gear Actuation: The largest mechanical hurdle for our group was determining how the gears

would be shifted, as this requires a large amount of force and relatively high precision. We wanted a system that would be self locking so that it would use far less energy and be more robust than a not self locking alternative. Our first goal was to decide how we

Page 4: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

3

would integrate the actuation with the derailleurs that were already on the bike. In order to reduce mechanical fabrication and maximize design flexibility we chose to use the standard shifter cable and apply the force via the cable, much like a normal derailleur works. We first considered high gear ratio, self locking, high torque DC motors as these met all of our design requirements. Unfortunately these motors proved far too expensive to be considered as a design alternative, so a new alternative had to be found. Ultimately we decided to use high torque RC motors, as these offered the required torque and resolution, further they offered simple position control. Servomotors do not offer the self-locking functionality desired; however, they were the most effective and affordable solution.

System Integration: It was very important that our final design integrated well with the bike, and so

significant effort was put into making sure everything fit well and looked good. The center of the bicycle was chosen to enclose and hold all major electrical components, as this area does not interfere with the cyclist. Mounting the servos in a non-intrusive manner proved to be challenging because mounting them in the main enclosure introduced added friction that the motors could not overcome. After much trial and error it was determined that mounting the servos as close to the derailleur as possible made them far more effective. To create an effective user interface, a “control unit” was built to mount on the handlebars. This unit offered a text display, three input buttons, and three shift notification lights. A button was also added to each handle, so the cyclist could shift without removing their hands from the handles.

Electrical:

Sensors: The basic quantities to be sensed were the rear wheel speed, crank speed, and the

tilt of the bike. To capture the rear wheel speed, 9 magnets were secured to the spokes of the rear wheel and a hall-effect sensor was mounted to the frame of the bike. The hall-effect sensor used was a digital on/off switch that simply pulsed from on to off in the presence of a magnetic field. This would generate pulses which could then be used by the microcontroller to determine wheel speed. The crank speed capture was a similar arrangement with a slight modification. For this sensor, a magnet and hall-effect sensor were placed facing each other in a fixed position with the largest crank sprocket between them. Instead of magnets moving in and out of the hall-effect sensor’s range to generate the pulses, the teeth of the crank sprocket would block the magnet’s field disruption to generate on/off pulses which could then be used by the microcontroller to determine crank speed. The final sensor used was the accelerometer to detect tilt. The accelerometer used was a 3 axis model with an output range of 0-3.3V. By positioning the accelerometer such that the y-axis was parallel to the ground and the x-axis was pointing up, the y-axis value indicated whether the bike was tilted up, on level ground, or tilted down by varying from some minimum value to a center value, or to some maximum value, respectively. These three sensors provided all the inputs necessary for the automatic shifting control algorithms.

Page 5: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

4

Power Supply: The power supply of the system was selected to be a 12V 2.3 Ah absorbed glass

mat (AGM) lead acid sealed battery. There were a number of advantages to using this battery. Common 12V car battery chargers could be used to recharge the battery. Also, lead acid batteries are capable of providing high current, and AGM batteries can be mounted in any orientation. The battery used is shown in Figure 1.

Figure 1: 12V 2.3 Ah AGM Battery

The microcontroller required a 12V input, which it regulated down to 5V. The

servo motors required 6V input, the hall-effect sensors required 5V input, and the accelerometer required 3.3V input. The varied power input requirements of the different components necessitated a number of regulatory circuits that will be discussed in detail in the electrical implementation section.

Implementation:

Mechanical:

Gear Actuation: To effectively shift the front and rear derailleur of the bike we used two high

torque RC servomotors (See Below).

Figure 2: Hitec Servos HS-7955TG Titanium Gear (left) and HS-5245MG BB (right)

Page 6: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

5

The front derailleur required higher torque to actuate, which ultimately required a more powerful servomotor. The servos were mounted directly to the bike frame using U-Bolts and servo mounts made of 1/8in steel plate on a water jet. The mountings can be found below in Figures 3 and 4.

Figure 3: Front servo mount

Figure 4: Rear servo mount

The original shift cable is attached to a spool on the servo, thus as the servo spins

the cable wraps around the spool causing the derailleur to move. A system was used that allowed for varying spool sizes, allowing adjustment of the total travel of the servo. By using a smaller spool, the maximum torque applied to the servo is decreased, reducing the wear on the servo.

The servos have an integrated controller with feedback that converts a PWM signal to an absolute position. This allowed for easy control, where each gear can be mapped to specific PWM signal and selected easily. Each servo was controlled by an individual PWM channel that can be updated at anytime by software, allowing for very effective real time shifting control.

User Interface: The user interface was composed of an LCD display that displayed the mode, current gear for the front and rear derailleurs, the speed and average speed of the bike, and also the total distance traveled. 5 buttons were integrated into the interface, including

Page 7: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

6

3 buttons next to the LCD and 2 on the handlebars, and 3 LEDs were placed on the other side of the LCD. Figures 5 and 6 shows the configuration of the user interface.

Figure 5: LCD Display

Figure 6: User Interface

1 2

3

4

5

Page 8: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

7

The five switches serve the following functions shown in Table 1.

Table 1: Switch Function Button Function

1 Down Shift (switch to manual mode) 2 Up Shift (switch to manual mode) 3 Toggle Mode 4 Toggle Avg. Speed / Current Speed 5 Clear Trip / Avg. Speed Values

The control unit also had three shift notification LEDs, which were used to warn

the bike that a shift is about to happen. These are important because the rider must be pedaling for a shift to occur. The LED “definitions” are shown in Table 2.

Table 2: LED Function

LED # Description 1 Shift Sequence Begun 2 Front Derailleur Moved 3 Rear Derailleur Moved

The combination of these three components allow for a very effective and

comprehensive user interface.

Main Enclosure: The main enclosure was designed to carry the microcontroller board, the daughterboard, and additional circuitry for the hall-effect sensors and the accelerometer. It was desirable for the enclosure to fit within the confines of the bicycle frame so that it would not interfere with the rider’s legs. Also, the enclosure needed to be aesthetically appealing and have easy access to the circuitry inside. Thus, a black opaque Plexiglas sheet was used to mount the microcontroller and daughterboard, and a clear Plexiglas sheet was used as the front cover of the enclosure. Countersink bolts in conjunction with U-brackets were used to mount the backing to the bicycle, and the front cover was attached by means of 3 butterfly nuts, thus allowing for the cover to be easily removed for maintenance. Figure 7 shows the main enclosure with the front cover removed.

Page 9: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

8

Figure 7: Main Enclosure

Sensor Mounting: The accelerometer was mounted inside the main enclosure so that it would be secure from possible disturbances. The mounting was provided with a crescent slit so that the position of the accelerometer could be adjusted. The rotational position of the sensor had to be perfectly level so that the data collected by the sensor was accurate. To do this, the accelerometer was calibrated using the SCI interface before the mounting screws were tightened. Figure 8 shows a close-up of the accelerometer mount.

Figure 8: Accelerometer Mount

The rear wheel hall-effect sensor was mounted onto the frame of the bicycle on the inner side as to reduce the risk of knocking it out of place. Two aluminum U-brackets were placed on the frame and the hall-effect circuit was attached to these brackets. The

Page 10: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

9

circuit was wrapped with electrical tape to enclose the circuit. Store-bought bicycle magnets were placed on the spokes of the rear wheel. The pedal crank hall-effect sensor was mounted using an aluminum bracket that enclosed both the sensor and the magnet, with the sensor on the inside side of the crank sprocket and the magnet on the outside side. This enclosure was attached to the frame of the bicycle by means of U-bolts. Figures 9 and 10 show the mounting of the two hall-effect sensors.

Figure 9: Rear Wheel Hall-Effect Sensor

Figure 10: Crank Speed Hall-Effect Sensor

Sensor

Magnet

Sprocket

Magnets (6x)

Sensor

Page 11: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

10

Battery Mounting: The battery was chosen to be mounted behind the seat of the rider. A store-bought bicycle pouch was chosen to enclose the battery. This pouch has a hard plastic top and bottom that protects the battery from damage. The wires from the battery were run outside of the pouch to the main enclosure and were secured to the frame along the way as to prevent the wires from getting caught in foreign objects. The enclosure is shown below.

Figure 11: Battery Mount

Electrical:

Sensors: The hall-effect sensors required a current limiting resistor and some circuitry to

filter noise. The value R of the current limiting resistor was calculated so that the current would be 5 mA. Thus, with a 5 V power supply, the resistance was chosen to be 1 kΩ. Capacitors were used to block the high and low frequency noise. A small board was printed using the circuit printing machine in the Mechatronics lab to provide a convenient means for implementing this circuitry and mounting it to the bicycle. The circuit diagram for the hall-effect sensor circuit and the corresponding board is shown below.

Figure 12: Hall-Effect Sensor Circuit Diagram

Page 12: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

11

Figure 13: Hall-Effect Sensor Circuit Board

The accelerometer used came as part of a small board that permitted easy

connection of wires to the board. The only additional circuitry required was a small RC filter for each output channel of the accelerometer. This RC filter was implemented on the Power and I/O board (daughterboard) to facilitate connection to the microcontroller.

Power Supply: The power supply required a number of regulator circuits to step the 12V battery

voltage down to 6V, 5V, and 3.3V. This was implemented on the Power and I/O board. The 3.3V regulator was the most straightforward to install as it needed to supply very little current and did not require any additional consideration for heat dissipation. The 6V supply needed to supply up to 2A of current for each motor. This mandated that the regulator circuit be able to dissipate up to 24W of power without failure. To accomplish this two separate 6V regulators were used with a large aluminum heat sink for each. The 6V regulators were selected based on their peak current rating of 2.2A with no heat sink. In testing, a single regulator mounted to a heat sink was able to drive a 2A load for several minutes without failure. This testing validated the 6V regulators for use and the Power and I/O board was designed around them. It was also determined at this time that the 5V supply for the Hall-effect sensors would be taken from the 6V regulated supply with a simple Zener diode regulation circuit. This circuit consists of a resistor in series with a reverse biased Zener diode as shown in Figure 14. This worked for our purposes because of the very low current draw of the Hall-effect sensors.

Once the various power supplies were nailed down, connectors were added to the

Power and I/O board to facilitate connection of the sensors and motor control to the microcontroller. It made sense to put the power and I/O on the same board since each

Figure 14: Zener diode regulator

Page 13: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

12

sensor or motor required power and a connection to the microcontroller. A circuit diagram of the entire Power and I/O board is shown in Appendix B. The final layout of the board is shown in Figure 15.

Figure 15: Power and I/O board

Interconnects: Given the mobile operating environment of our system, special attention was paid

to all electrical interconnects to ensure quality and reliability of all connections to the microcontroller, power and I/O board, sensors, and motors. To accomplish this, two special header boards, on the right of Figure 15, were made using the circuit routing machine in the lab to allow solder connection of wires to a 40 pin dual line header. These specially made connectors facilitated reliable connection of all wiring to the microcontroller. All other connections were made using positive locking and polarized connectors from Molex SL series. These connectors increased the cost of the project, but proved their worth during the debugging phase as they permitted easy disconnection of individual components to isolate specific components for testing. Additionally, they facilitated a neat and clean installation of the components.

User Interface: The user interface consisted of three major components, which were the LCD

display, switches, and LEDs. The LCD was a standard 4X20 character display, controlled using parallel communication. The display gives visual feedback of important information, such as the control mode, current front and rear gear, current speed, average speed, and distance traveled. The bike used five push button switches are connected to input capture pins on the microcontroller. Each switch utilized the de-bouncing circuit shown in Figure 16.

Page 14: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

13

Figure 16: Switch De-bouncing Circuit Diagram

The circuit shown in figure 16 was used to reduce bounce that can be caused by push button switches and human error.

Software:

Back End Code: The software to power the system was written to take full advantage of the

microcontroller’s built in features, such as timers, interrupts, and PWM. This was done to keep the code as lean, efficient, and responsive as possible. In fact, the main loop of the function is empty; the program is purely interrupt driven.

Two main timers were used in the program. The first timer was the periodic interrupt timer, which could be used to trigger the analog to digital conversion sequence. The periodic interrupt timer was configured to trigger the analog to digital conversion of the three accelerometer outputs once every millisecond. The timer also generated an interrupt every millisecond in which the accelerometer data was averaged over 500 samples. The second timer was the modulus down counter in the Enhanced capture timer module. This timer was set to count down to a zero value every second. This timer could also be configured to latch the pulse accumulator values to a holding register every 1 second. As a result, no special code needed to be written to capture the pulse accumulator values when the timer reached zero. The down counter was also used to trigger an interrupt which contained the update functions for the LCD display as well as the shifting logic. This was done to ensure that the shifting did not occur too frequently and that the LCD display update did not consume more system resources than necessary.

Two uses of the interrupt feature have already been described, and another use was to capture the input from 5 push buttons used to interface with the rider. Each button triggered an interrupt which contained the code to handle the user request.

The PWM feature was used to control the servo motors used to actuate the derailleurs. The servo motors responded to a pulse width of 0.9ms to 2.1ms. This made use of the PWM module a natural fit. The PWM was configured to provide a pulse width of 0 to 2.2ms. This ensured that the motors could be fully actuated. Control of the motor was simplified to writing a value to the PWM duty cycle register for each motor.

5 V

To MC

Page 15: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

14

Using the hardware features of the microcontroller greatly simplified the coding required to make this project work. The focus on using hardware features also improved the overall function of the code by permitting the peripheral modules to handle tasks that would otherwise have required core CPU cycles to execute.

Front End Code: Once the above interrupts and modules are configured the next step was to create

functions that take advantage of the modules. The first important function is a “change gear” function, when called this function updates the PWMs signal to actuate the servo, illuminates the shift LEDs, and updates gear positions. A flow diagram for the function can be found in Figure A-2 of Appendix A. An important thing to note about this function is that it will not shift unless the cyclist is pedaling, which is important to avoid derailing. And important part of the change gear functions is having an effective mapping of gear number, to PWM on time, shown below in Table 3.

Table 3: PWM On Times for Each Gear

Front Gear On Time Rear Gear On Time 1 0x5F 1 0x5F 2 0xBA 2 0x74 3 0x03 3 0x92 4 0xAF 5 0xC9 6 0xFF

A large part of the code was dedicated to running and updating the LCD display.

An LCD update function was created that:

• Updates the trip value • Updates current velocity or average velocity • Updates current gear

o Front Value o Rear Value

This function caused some problems due to latency with the display that was

disrupting other code. In order to avoid issues the LCD update function is only called once per second. The driver used to control the LCD display was adapted from [1].

The final portion of code developed was the controller, which used sensor data to intelligently shift through the gears. We decided to offer three different controls:

1. Auto Cadence: Shifts Based Solely on pedal speed 2. Auto Force: Shifts based on pedal speed and angle of inclination. 3. Manual: Shifting controlled by push button.

An in depth flow chart for all three controllers can be found in Figure A-1 of Appendix A. The cadence controller takes pedal speed as an input and compares the value to a threshold. If the value does not lie in the threshold then the controller calls the shift

Page 16: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

15

function. The force controller is the same cadence controller, however in addition to speed the force controller monitors changes in tilt. Every time the force controller is called it compares the current tilt to previous tilt, if the magnitude has change greater than the allowable threshold the controller will shift twice. The force controller is our effort to achieve a “feed-forward” effect. For our application it was important that the LCD update function and controllers were run routinely on a set time interval, to accomplish this the modulus down counter was set to fire once every second. This counter calls an interrupt that calls the LCD update and control functions.

Hardware:

Table 3: Hardware Component List Name / Description: Part Number Cost ($) Qty. Accelerometer MMA7260Q $25.00 1 Hall-Effect Sensor ATS137PL $1.00 2 LCD Display HC-LCD $40.00 1 Front Servo HS-7955TG Titanium Gear $55.00 1 Rear Servo HS-5245MG BB $125.00 1 Battery SLAA12-2.2F $20.00 1 Micro Controller DEMO9S12XEP100 Borrowed 1

Future Work: Several further steps can be taking in the future to improve this project. The controller adequately controls the gear shifting, but it is not perfect. A new controller could be created that takes into account pedal acceleration and torque in addition to pedal speed and tilt, much like the original controller was imagined. Further refining of the current controller parameters could also prove beneficial to creating a better control scheme. Also, allowing for customization of the controller for different pedaling styles such as BMX or racing could be a very useful tool in making a better controller. Another aspect of this project that could be improved in the future is the actuation method. Certain gear combinations were not practical to include in the control scheme due to their inconsistency. This problem could be fixed by investing in better motors than the servomotors that were used, or by adjusting the settings of the derailleurs and tension cables. New motors may also reduce the power consumption of the system. These newer motors should be self-locking as to meet one of the criterion for the motors that was not able to be met. Another option to improve the gear actuation would be to replace the current derailleurs with a more effective shifting mechanism or to remove the spring back function of the current derailleurs. This would enable easier actuation using the current servomotors. In addition to control schemes, the user interface could be improved by replacing the LCD and LED’s with better products as to improve the aesthetics and ease of use of the bicycle. Implementation of this product on different bicycles would also be a goal for

Page 17: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

16

future work as to show the practicality of the design and its application for normal sized bicycles.

Conclusion: The objective of this project was to create an automatic transmission for a common bicycle. The specific goals of that objective were fulfilled with great success. The system was able to shift the bicycle smoothly through the gears of the bicycle using both a manual button-activated mode and an automatic mode that incorporated the pedaling rate, bike speed, and tilt. The user interface effectively provides the rider with a view of his/her speed, current gear, and distance traveled, and it also allowed an easy means of changing between manual and automatic and shifting while in manual mode. The controller used was effective in changing gears to accommodate the rider’s needs. However, this controller has significant room for improvement as there are many factors involved in the system that were not able to be taken into account. The bicycle project was built while within a reasonable budget, thus adding to its feasibility and marketability. Overall, the Awesome Automatic Bicycle Transmission exceeded the group expectations and is considered a great success.

References: [1] http://www.piclist.com/techref/microchip/language/c/io/lcd/hitachilcd-cl/lcd_c.htm.

Page 18: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

17

Appendix A:

Figure A-1: Controller Flow Chart

Figure A-2: Shifting Algorithm Flow Chart

Shift Front Gear

LED 2 ON

Are they pedaling?

LED 1 ONAll LED's

OFF

Wait for reargear to shift

Shift Rear Gear

Are theypedaling? LED 3 ONWait for front

gear to shift

Is Shift Up/Shift Down

Command Given?

Yes

Yes

Yes

Shift DOWNIs Change

tilt 0.153g?

Is Mode =AutoForce?

Tilt

Is change intilt

0.153g?Shift UP

Is crankspeed >

50?

Is crankspeed <

30?

Yes Yes

Yes

Yes

Yes

Crank Speed

Is Mode =Manual?

No

Yes

Mode = Manual

Button 1Pushed?

Yes

Mode = Manual

Button 2Pushed?

2x

2x

Page 19: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

18

Appendix B:

Figure B-1: Circuit Diagram of Power and I/O Daughterboard

LM 7806A

12 V 220μF 220μ F

To PP0

To PT0

PWM 1

300 Ω

Hall 1

LM 7806A

12 V

220 μF 220 μF

To PP1

To PT1

PWM 1

300 Ω

Hall 1

UA 78M33C

12 V

220 μF 220 μF

IN4007

SIP GS2 GS1

x y z(from Accel)

1 k Ω

1 k Ω

1 k Ω

3

x

1

(from Accel)

(from Accel)

0.1 μF

6 V 6 V 3.3 V

0.1 μF

To PAD0

To PAD1

0.1 μF

To PAD2

Page 20: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

19

Appendix C: #include <hidef.h> /* common defines and macros */ #include <MC9S12XEP100.h> /* derivative information */ #pragma LINK_INFO DERIVATIVE "mc9s12xep100" #define LCD_RS PORTB_PB0 // Register select #define LCD_EN PORTB_PB1 // Enable #define LCD_D4 PORTB_PB2 // Data bits #define LCD_D5 PORTB_PB3 // Data bits #define LCD_D6 PORTB_PB4 // Data bits #define LCD_D7 PORTB_PB5 // Data bits #define LCD_STROBE ((LCD_EN = 1),(LCD_EN = 0)) #define C1 0.2093 //Coeffs for Force Calc #define C2 1.1036 #define C3 .0091201 #define C4 1804.8 #define LED3 PORTB_PB6 #define LED2 PTM_PTM1 #define LED1 PTM_PTM0 //Define Global Variables long Velocity=0, OldVelocity=0, Acceleration=0, tilt=0,LowCutOffTPS=30,HighCutOffTPS=50,OldY=0; float TotalTime=0, Trip=0, ts=1; char Mode=3, SpeedMode=1; //1==>Automatic, 1==>Current Speed int c=3, FrontGear=1,RearGear=1,i=0, Gears=9; unsigned long xyz[3]=0,0,0, //used to hold running sums of accelerometer //x, y, and z channels xyzAvg[3]=0,0,0; //holds averaged value of accelerometer data //updated periodically (numAvgs*periodic timer) const int numAvgs=500; //determines how many averages to make int avgs=0; //counter for number of averages taken const float GearInc[3][9] = 1,1,1,1,3,2,2,3,3, 5,4,3,2,5,3,2,3,2, 0,0,0,0,0,0,0,0,0 ; long del; void init_registers(void) //This functions sets up the PIT, ATD, and SCI modules. DDRJ = 0xC0; PTJ = 0x00; //SCI setup SCI0BDH = 0x00; //Disables IR SCI0BDL = 0x34; //Sets SCI baud rate to 19200 (16Mhz / (16 * 52)) SCI0CR1 = 0x00; //8bit data, no parity SCI0CR2 = 0x2C; //Receive data register full interrupt

Page 21: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

20

enabled //Transmit & receive enabled //ATD setup ATD0CTL0 = 0x02; //sets the ATD module to wrap to channel 0 after sampling channel 7 //(PAD00 - PAD07 on board Pins[24 22 20 18 16 14 12 10] on J101) ATD0CTL1 = 0xD2; //Enables external trigger select for ATD conversion //Sets ATD resolution to 12bit //Enables sample discharge //Selects external trigger two (ETRIG2 = periodic interrupt timer channel 0) ATD0CTL2 = 0x0C; //Enables external trigger for ATD conversion //One conversion sequence per rising edge on trigger ATD0CTL3 = 0xC0; //sets the data result registers to right justify. //sets the conversion sequence length to 8 (one conversion sequence will scan //8 channels, 0-7) ATD0CTL4 = 0xE0; //Sets the sample time to 24 and the ATD clock prescaler to zero //ATD clock = fbus / (2 *(prescaler + 1)) //in this case, ATD clock = 8mhz, max sample + conversion time = 0.000336s ATD0CTL5 = 0x10; //Enables multiple channel scan //Starts scan on channel 0 //ECT setup ECT_TSCR1 = 0x88; //Enables the regular timer & precision timer ECT_MCCTL = 0xC0; //Enables Modulous Mode of modulous counter and enables modulus counter interrupt ECT_PTMCPSR = 0xFF; //Sets Modulous Down counter prescaler to 256: //counter speed = bus speed / prescaler ECT_MCCNT = 0xF424; //Sets counter value to 62500, which gives exactly 1s countdown time ECT_TCTL4 = 0x05; //Sets Pulse Accumulator 0 & 1 (PAC0 & PAC1) to increment on rising edges only //(use pin PT0 & PT1, pin 13 & 15 on J101) ECT_ICSYS = 0x07; //Sets max value of pulse accumulator to 255, will not roll over //Enables holding registers for pulse accumulators //Enables latching of pulse accumulators to modulous down counter //Input Capture setup ECT_TIOS = 0x00; //Sets pins to input capture mode ECT_TCTL3 = 0x15; //Sets IOC 6, 5, 4 to capture on rising edges. ECT_TCTL4 = 0x55; //Sets IOC 3, 2 and PAC 0 & 1 to capture on rising edges. ECT_TIE = 0x7C; //Enables interrupts for IOC 6, 5, 4, 3, 2 //PIT setup

Page 22: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

21

PITCFLMT = 0x00; //Turns off PIT PITCE = 0x01; //Enables periodic interrupt timer channel 0 PITMUX = 0x0; //Uses 8bit micro timer channel 0 for all timer channels //The following combination of micro timer & timer should yeild a 1ms periodic pulse. //Where fbus = 16mhz for the board being used //period = (PITMTLD0 + 1) * (PITLD0 +1)/ fbus PITMTLD0 = 0x01; //Sets the 8bit micro timer channel 0 to 1 (0x01) PITLD0 = 0x1F3F; //Sets the 16bit timer channel 0 to 7999 (0x1F3F) //PWM setup PWMPOL = 0x03; //Sets the Polarity of PWM 0 & 1 to positive PWMCLK = 0x03; //Sets PWM 0 & 1 to use Clock SA PWMPRCLK = 0x00; //Sets Clock A prescaler to 2: Clock A = Bus clock / PWMPRCLK PWMSCLA = 0x45; //Sets Clock SA prescaler to 69: Clock SA = Clock A / (2 * PWMSCLA) PWMPER0 = 0xFF; //Sets PWM0 period to 255 PWMPER1 = 0xFF; //Sets PWM1 period to 255 PWMDTY0 = 0x5f; //initializes PWM0 duty cycle to 0/255 PWMDTY1 = 0x5F; //initializes PWM1 duty cycle to 0/255 //Enable & Turn on modules PITINTE = 0x1; //Enables an interrupt for periodic interrupt timer channel 0 PWME = 0x03; //Enables PWM0 & PWM1; PITCFLMT = 0x80; //Enables the periodic interrupt timer ECT_MCCTL = ECT_MCCTL | 0x04; //Turns on Modulous counter ECT_ICPAR = 0x03; //Enables PAC0 & PAC1 //ECT_PA0H holds the latched value of the pulse accumulator //ECT_PACN0 holds the real time value of the pulse accumulator //Configure Port M DDRM=0xFF; //Set for Output LED1=1; //Turn off LEDS LED2=1; LED3=1; unsigned char toASCII(unsigned char value) //This function converts hexadecimal digits to ASCII code value = value & 0x0F; if (value<10) return value + 48; else return value + 55;

Page 23: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

22

void interrupt 0x14 SCI0_ISR(void) //insert code to handle SCI interrupt here void interrupt 0x42 PIT0_ISR(void) //This function services the Periodic timer interrupt //put code here that you want to execute every time the timer reaches zero if (avgs == numAvgs) xyzAvg[0] = xyz[0] / numAvgs; xyzAvg[1] = xyz[1] / numAvgs; xyzAvg[2] = xyz[2] / numAvgs; xyz[0] = 0; xyz[1] = 0; xyz[2] = 0; avgs = 0; else xyz[0] = xyz[0] + ATD0DR2; xyz[1] = xyz[1] + ATD0DR1; xyz[2] = xyz[2] + ATD0DR0; avgs++; void ChangeGear() //Shifting Function long OnTimeArrayFront[3]=0x5F,0xBA,0x03; long OnTimeArrayRear[6]=0x5F,0x74,0x92,0xAF,0xC9,0xff; FrontGear=(int)(GearInc[0][c]); RearGear=(int)(GearInc[1][c]); LED1=0; //Turn on LED1 if (PWMDTY0!=OnTimeArrayFront[FrontGear-1]) //check if the deraileur is moving while (ECT_PA0H<5); //Wait until they are pedaling LED2=0; //Turn on LED2 PWMDTY0=(unsigned char)(OnTimeArrayFront[FrontGear-1]); //Change Front Gear for(del=0;del<50000;del++); //wait else LED2=0; if (PWMDTY1!=OnTimeArrayRear[RearGear-1]) //check if the deraileur is moving while (ECT_PA0H<5); //Make Sure they are still pedaling LED3=0; //Turn on LED3 PWMDTY1=(unsigned char)(OnTimeArrayRear[RearGear-1]); //Change Rear Gear for(del=0;del<50000;del++); //Wait LED1=1; LED2=1; LED3=1; //Turn off LEDs void ShiftUp() if (c==3) c++;

Page 24: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

23

ChangeGear(); else if(c<Gears-1) c++; ChangeGear(); void ShiftDown() if(c>0)c--; ChangeGear(); void ModeToggle() if (Mode==1)Mode++; else Mode=1; void interrupt 0x0A IOC2_ISR(void) ShiftUp(); Mode=3; ECT_TFLG1 = 0x04; void interrupt 0x0B IOC3_ISR(void) ShiftDown(); Mode=3; ECT_TFLG1 = 0x08; void interrupt 0x0C IOC4_ISR(void) ModeToggle(); ECT_TFLG1 = 0x10; void interrupt 0x0D IOC5_ISR(void) SpeedMode=SpeedMode^1; ECT_TFLG1 = 0x20; void interrupt 0x0E IOC6_ISR(void) TotalTime=0; Trip=0; ECT_TFLG1 = 0x40; void ForceController(void) //Calculate Pedaling Force long Fe; int G; G = (int)(GearInc[2][c]); //sets gear ratio according to current gear Fe = C1 * Acceleration / (G * ts) + C2 * tilt + C3 * Velocity * Velocity / (ts*ts) - C4; Acceleration = Velocity - OldVelocity; //updates acceleration if (Fe > 600) ShiftDown(); //if effort too much, shift down

Page 25: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

24

else if (Fe < 400) ShiftUp(); //if effort too easy, shift up else ;//if effort in allowable range, do nothing void CadanceController() if (ECT_PA0H<LowCutOffTPS) ShiftDown(); else if (ECT_PA0H>HighCutOffTPS) ShiftUp(); float SpeedCalc() //Calculate Speed in MPH float SpeedMPH; SpeedMPH = (float) (ECT_PA1H * .00128*3600 / (ts)); return SpeedMPH; float AVGSpeedCalc() //Calculate Average Speed in MPH float AVGSpeedMPH; AVGSpeedMPH = (float)(Trip * .00128*3600 / TotalTime); return AVGSpeedMPH; //LCD FUNCTIONS void lcd_write(unsigned char c) //write a byte to the LCD in 4 bit mode if(c & 0x80) LCD_D7=1; else LCD_D7=0; if(c & 0x40) LCD_D6=1; else LCD_D6=0; if(c & 0x20) LCD_D5=1; else LCD_D5=0; if(c & 0x10) LCD_D4=1; else LCD_D4=0; LCD_STROBE; for(del=0;del<250;del++); if(c & 0x08) LCD_D7=1; else LCD_D7=0; if(c & 0x04) LCD_D6=1; else LCD_D6=0; if(c & 0x02)

Page 26: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

25

LCD_D5=1; else LCD_D5=0; if(c & 0x01) LCD_D4=1; else LCD_D4=0; LCD_STROBE; for(del=0;del<250;del++); void lcd_putch(unsigned char c) /*write a char*/ LCD_RS = 1; lcd_write(c); void lcd_clear(void) //Clear and home the LCD LCD_RS = 0; lcd_write(0x1); for(del=0;del<250;del++); void lcd_puts(const char * s) //write a string of chars to the LCD LCD_RS = 1; // write characters while(*s) lcd_write(*s++); void lcd_goto(unsigned char pos) //Go to the specified position LCD_RS = 0; lcd_write(0x80 + pos); void lcd_init(void) /* initialise the LCD - put into 4 bit mode */ DDRB=0xFF; LCD_RS = 0; // write control bytes for(del=0;del<1000;del++);// power on delay LCD_D4 = 1; // init! LCD_D5 = 1; // LCD_STROBE; for(del=0;del<1000;del++); LCD_STROBE; // init! for(del=0;del<1000;del++); LCD_STROBE; // init! for(del=0;del<1000;del++); LCD_D4 = 0; // set 4 bit mode LCD_STROBE; for(del=0;del<1000;del++); lcd_write(0x50);// 4 bit mode, 1/16 duty, 5x8 font, 2lines lcd_write(0x0C);// display on lcd_write(0x06);// entry mode advance cursor lcd_write(0x01);// clear display and reset cursor void lcd_write_num(int pos,char dec, char len, long value) int dig[4], i; dig[3] = (int)((value % 10)); value = value / 10;

Page 27: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

26

dig[2] = (int)((value % 10)); value = value / 10; dig[1] = (int)((value % 10)); value = value / 10; dig[0] = (int)((value % 10)); lcd_goto((unsigned char)pos); for(i=4-len;i<4;i++) if (i==4-dec) lcd_puts("."); lcd_putch(dig[i]+0x30); void LCD_Startup() for(del=0;del<5000;del++); lcd_init(); lcd_clear(); lcd_puts("Mode: Automatic"); lcd_goto(40); lcd_puts("Speed: 00.0 mph"); lcd_goto(20); lcd_puts("Trip: 00.0 mi"); lcd_goto(84); lcd_puts("Front:1 Back:1"); void LCD_Update() lcd_goto(6); if (Mode==1) lcd_puts("AutoForce "); else if (Mode==2) lcd_puts("AutoCadance"); else lcd_puts("Manual "); lcd_goto(40); if (SpeedMode==1) lcd_puts("Speed: MPH "); lcd_write_num(47,1, 3, SpeedCalc()); else lcd_puts("Avg Speed: MPH"); lcd_write_num(51,1, 3, AVGSpeedCalc()); lcd_write_num(26,2, 4, (float)(Trip * .0128)); lcd_write_num(90,5, 1, FrontGear); lcd_write_num(98,5, 1, RearGear); lcd_write_num(18,5, 2, (float)(c)); void interrupt 0x1A MODCNT_ISR(void) int i=0; unsigned char *accel_pt; OldVelocity = Velocity; Velocity = ECT_PA1H; Trip = Trip + ECT_PA1H; TotalTime=TotalTime+1; while (!SCI0SR1_TDRE); //waits for transmit data

Page 28: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

27

register to empty SCI0DRL = toASCII((ECT_PA0H) >> 4); //transmits high nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(ECT_PA0H); //transmits low nibble of high byte while (!SCI0SR1_TDRE); SCI0DRL = ' '; while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII((ECT_PA1H) >> 4); //transmits high nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(ECT_PA1H); //transmits low nibble of high byte while(!SCI0SR1_TDRE); SCI0DRL = ' '; for (i =0; i<3; i++) accel_pt = &xyzAvg[i]; while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII((accel_pt[0]) >> 4); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(accel_pt[0]); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII((accel_pt[1]) >> 4); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(accel_pt[1]); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII((accel_pt[2]) >> 4); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(accel_pt[2]); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII((accel_pt[3]) >> 4); //transmits low nibble of high byte while (!SCI0SR1_TDRE); //waits for transmit data register to empty SCI0DRL = toASCII(accel_pt[3]); //transmits low nibble of high byte while (!SCI0SR1_TDRE); SCI0DRL = ' ';

Page 29: Final Report Rev3 - gatech.eduume.gatech.edu/mechatronics_lab/Projects/Fall08/Group3/... · 2009. 4. 21. · ME 8843 - Advanced Mechatronics Dr. Ume Spring 2009 Final Report - Automatic

28

SCI0DRL = '\n'; ECT_MCFLG = 0x80; if (OldY>xyzAvg[1]+100 && Mode==1) ShiftDown(); ShiftDown(); else if (OldY<xyzAvg[1]-100 && Mode==1) ShiftUp(); ShiftUp(); OldY=xyzAvg[1]; LCD_Update(); if (Mode==2 || Mode==1) CadanceController(); void main(void) LCD_Startup(); init_registers(); EnableInterrupts; for(;;) //do nothing