Acceration Robot

An acceleration robot

Pekka Ritamaki, OH3GDO

Kuva1.jpg

Picture 1 A BS-Mileage team. A writer at top right.

Electronics and motors for 50 years

When I was ten years old, I was interested in electronics and radios. My mate Esa was interested in motors, cars and boats.
We build constantly projects together.
I tried to find a person who could explain transistor circuits to me. I looked for the best men in the field. They were working in the local paper factory as instrument department. I teased one after other every day with my questions until they directed me to next specialist. When I was 12 years old, I found that I must look better people. Then I found a house, which had a moving antenna. The antenna was bigger than the house. The local radio amateur Reino, OH1TN, had done every piece of his radio amateur station himself. His profession was a lumberjack. Finally I found the answers.

After 50 year I still build electronics every day and Esa is working with motors in his shop. Reino is still living at the same location inside his antenna forest, which is increased to two kilometres.

The acceleration robot

The motors are not my main interest. Still I have build hundreds of motor related projects. Here I want to show a little but interesting project: an acceleration robot for economical motor competition. This robot start the vehicle automatically, controls the acceleration as taught. It can be moved to a motorbike or Formula 1 for Kimi’s Ferrari.

First I will tell about vehicles for Mileage Marathon Competition. Then I show a block diagram of acceleration robot and tell why this device does. A schematic diagram is explained shortly. The lack of IO-pins is solved with a clever way.
I introduce a new Tampere-style real-time programming style. At finally servo hardware for motor control is explained.
Although this is not a building article, I have included everything: a schematic files, a PCB assembly file, top and bottom layers in PDF, a parts list in Excel, c-source code and HEX file. If you don’t compete against me, please read carefully the Tampere style software part.

The competition vehicle

Kuva2.jpg

Picture 2 a competition in France 2002

The aim of the Shell Eco Marathon competition is to find extreme low mileage in combustion engines. BS-Mileage Marathon team (Ref 1) won a new world record in diesel class 2006:
Our BS03 Velociraptor (a fast dinosaurs) made 2664 km/litre or 7525 miles per gallon. To achieve this, every small detail must be taken account. Our vehicle has a modified 199 cc 2.5kW diesel engine. Two 20” radial wheels in front a rear wheel linked to the motor with chain without gear. A high durability steel body of the vehicle weights 4 kg (8.8lb). Each kilogram means 0.5% of the result. The total weight is 65 kg (143 lb). A 35 ml (2 cu in) fuel tank is filled before and after each lap and the temperature is measured before and after the competition.
The minimum mean speed is 35 km/h (22 miles/h). The optimum run is to keep speed constant for each lap. One competition lap is about 20 km (12 miles). The competitions are held in different counties. They have different hills. A driver must weight 45kg (99 lb) at least. Shell sponsors fuel, about 10ml (0.6 cu in) for 20 km (12 miles) for all the teams.

The economic drive style

The combustion engines run the most economically only at one rpm. In our vehicle it is 2400 rpm. The motor is off the most time of the lap. The motor is needed only in hills. The driver must know exactly when and how to accelerate to so that the total time of the lap is optimum. For the driver this is very difficult. After the motor is started, it must go to economic rpm at minimum time. The race circuit consists of many slopes, which are not easy to master even with the experienced driver. The solution is an acceleration robot. It is taught how to control the engine at each uphill slope. The driver must only to select a right hill.

The starting sequence

Kuva3.jpg

Drawing 1. A height profile of the hill, a speed profile, an rpm profile and starter timing for one hill.

Look the Drawing 1. It shows a typical sequence of the motor. The aim is constant lap timing. The motor is started when the speed is 12 km/h. It happens in upward hills.
The starter is on until the vehicle runs at 650 rpm. The acceleration profile is divided to 8 time slots. The motor moves from one profile to other smoothly again with 8 steps. There is seven automatic profiles plus one manual profile. This profile is adjusted with potentiometers manually.
After the best rpm is achieved, the motor runs at most economical rpm. When the 65km/h is achieved the motor is stopped. Because there is no gear, the RPM is directly related to speed.
Each profile is taught by profile potentiometers. The sequence is selected by push buttons and indicated by a led. The timing and power profile is saved to EPROM of the cpu.

Kuva4.jpg

Drawing 2. A handwritten block diagram of the acceleration robot.

A block diagram

See the Drawing 2. A servomotor controls rpm of the diesel engine by adjusting the throttle lever of the carburettor. A Hall-sensor looks motor rpm. An auxiliary relay controls the starter motor. A PIO16F877A CPU is selected, because it had the most IO in the Microchip Flash CPU range in year 2001. The manual control panel has eight push buttons, eight LEDs and eight potentiometers. External EEPROM was available, but not used. The original circuit board do not had panel pcb. It was made it for easier mechanical assembly. Two PCBs are put together to form a sandwich.

A schematic diagram

Kuva5.jpg

Drawing 3. A schematic diagram of the acceleration robot

See drawing 3. A schematic diagram is very simple. A servo pwm, a Hall sensor input and a starter relay are only interface to outside world. A 12-volt battery is the main power supply. Five volt and 6-7.2 V servo power supply are done in the PCB-board. We used 7.2 V, but I can’t recommend I. It is out of specifications of the manufacturer.
Because the servo power supply is higher than 5V, an interface transistor is needed. A 12-volt power relay needs also an interface transistor. The serial connection to PC is done in UART level without RS-232 converter.

Kuva6.jpg

Drawing 4. A operation panel has 24 IO.

A operation panel, see drawing 4, is more complicated.
For the settings of all the controls I needed eight analog potentiometers, eight LEDs, eight push buttons and some common I/Os like RS485 for saving and loading good profiles from and to PC.

Kuva7.jpg

Drawing 5. Smart IO connections save pins in the CPU.

See drawing 5. Thirty-five IO-pins of PIC16F877A CPU were not enough. I found some ideas: A clever scheme for using many push buttons with an analogue I/O pin. It however uses approximately 100 us for each keyboard checking. During fast servo operation, I do not have that time available. I solved the problem combining LED indications and push buttons. A LED, a series resistor and a push button is put in series. IO-pin is connected between the resistor and push button. Normally the operation of the LEDs are controlled by an I/O pins. Changing a pin direction register, TRIS in PIC CPU, the I/O-pin can be read in less than one microsecond.

A block diagram of software

Kuva8.jpg

Drawing 6. A software block diagram

See drawing 6. The code of the unit is done for CCS PCW c-complier. Any c-source code it is easily converted to any other c-dialect, so the dialect is not a problem.
This program can’t be done in one sequence. There is a parallel operation for a human interface, the hall sensor counter, servo sequence and servo pulses. The interrupt Timer1 handles slower power sequences of servo. Timer0 interrupt handles the faster servo operation needed for analogue servos. See the servo operation chapter for the details.

At power up reset the timers, IO-Tris registers and interrupts are set to suitable values of this application. At start-up there are two special routines. If the button1 is pressed at the start-up, the settings are print to UART and PC. If the button2 is pressed in the reset, the timing rpm-limit value for the starter relay is recorded with the potentiometer 1. The timings in power sequence are recorded at the same time with the potentiometers 2-8.

The normal code waits for any button to close.

The save-button puts the code in a learning mode and it blinks the save-LED. When one of the buttons (1-7) is pressed, eight potentiometer values are saved as a power ramp values to eeprom. The last button (8) is used as a manual control mode.

Other keys start one of power sequences. First the starter relay starts the motor. The hall sensor counts revolutions with the Timer1. When the predefined value of rpm is reached, the starter relay drops. The power profiles from the eeprom is used to set servo position value.
The Timer0 controls the servo sequence. It has three phases:
• A 18 ms idle time
• A 0.5ms start pulse
• A 0-1.0 ms position pulse time

The Timer0 reloads each sequence independently.
These two timers work in background, without help of the main code. One sequence is divided to eight sub sequences to make a smooth acceleration. The driver stops the diesel engine manually when the speed is enough, mostly 65 km/h.

A restart is prevented during 1.28 s of the last start.

The code for button read and LED control is very simple. Look at this simplified C-code: Look also the connection principle in drawing 5.

#BYTE PORTB = 6
/* this Button code return if any key is pressed with key code */
int readButtons(void) {
int mode;
set_tris_b( 0xff); // set TRIS as inputs for buttons
buttons= ~PORTB; // invert the buttons in one microsecond
set_tris_b( 0); // set TRIS as output, this restores LEDs
switch(buttons) {
case 0x80: mode =0; break; //1. button for direct pot drive
case 0x40: mode =1;break; //2. button for 1. memory drive
case 0x20: mode =2;break; //3. button for 2. memory drive
case 0x10: mode =3;break; //4. button for 3. memory drive
case 0x8: mode =4;break; //5. button for 4. memory drive
case 0x4: mode =5;break; //6. button for 5. memory drive
case 0x2: mode =6;break; //7. button for 6. memory drive
case 0x1: mode =7;break; //8. button for 7. memory drive
case 0: return 0;break;
}
return mode;
}

Code1. readButtons() IO-routine

Reading the buttons takes only 1 us. If button is found, switch case is done in few code lines to return decoded button number. The routine selects the power sequence starting address for eeprom. No extra I/O-pins are needed for eight keys. This scheme works very fast. The keyboard debouching is done in the software.
This scheme is very simple and hopefully others can use it when the IO-pins are rare.

When the button is pressed, the motor of the vehicle is started if the motor is not running already. There must be a 1.28 second delay after motor run. When the speed of the motor is preset, normally 650 RPM, the starter is tuned off. The power profile of the motor is sequenced in Timer1.

The pushed button then selects the right power sequence. The starter motor is on until the rpm of the motor is enough to keep diesel engine running without help of the starter.
The eight steps of the power profiles are read from EEPROM in the 10 ms timer1 interrupt routine.
The profile smoothed again with eight sub steps. The calcPowerTable() routine calculates the power and timing in small steps. The power value controls the servo routine in Timer0 interrupt.

Parallel code principle

Kuva9.jpg

Drawing 7. A real time code principle: Tampere style

The multitasking code executive has been traditionally used to handle real time process controls. They switch the tasks in 1-10ms. This doesn’t work well. Task switching takes too much resource from microprocessors. The whole idea of task switching for fast operation is doomed. I can understand if it is used to solve coding bottleneck for the inexperienced freshmen. Task switching has always been too slow in my projects.

I have used so called Tampere-style. See Drawing 6.

The fast IOs are handled in dedicated units in the cpu. Such as PWM, counters, timers, UART, USB, CAN, Ethernet. The code in the interrupt routines is as small as possible. Only when they have something to tell, they inform main task or state machine with indication mailboxes. The mailbox is simply a bit or byte in the global structure. Some programmers do not prefer global variables. In small microprocessors the stack is small. The stack of Microchip PIC18F877A has only eight levels. The parameter passing using many levels of nested subroutines overflows the stack quickly. Use variables in c-style structures at global level. This maintains the readability and keeps the stack out of the limits.

The state machine has only few simple duties:
- Read the input bits and mailboxes
- A state machine works in one state at time. Check if some IO-task needs attention. Decode messages and calculate the results.
- Move to the next state according the predefined table
- Set the outputs according the results

This seems almost the same as the PLC operation (PLC = programmable logic controller). PLCs have always worked well, if the ready-made units are available. If not, you are in the trouble. The intelligent people are needed to develop these units for the PLCs. If you had read to this far of the article, you are capable making the your special case hardware and software.

Using the few simple rules described above, any decent programmer can make a good, real time device and prepare the code for that device.

The explosion of the state machine

Kuva10.jpg

Drawing 8. The explosion of the state machine

If the state machine comes too complicated, there is a possibility of the explosion of the state machine, see the drawing 8. It means that the developer can’t handle all the possible states in his mind. The monster state machines must divide to smaller state machines, which are easier to handle.

The testing the code with real thing

What then if the used CPU do not have the needed hardware resource? Most of the cases the CPU is selected according the cheap price tag. I say: “I want the most expensive CPU for the task”. This will help my development work to build the first prototype. If the first prototype works, maybe a smaller CPU can do the same task. If the first prototype does not work, because it is selected by wrong arguments, you newer get a second chance. Why I had problem with IO-count in the acceleration robot? Well in year 2001, this was biggest CPU in the Microchip flash CPU range.
Why I do not obey Tampere-style in my code? Well, I invented Tampere style when I was teaching students for Worlds Skills competition. It is held in Osaka, November 2007. I hope that one of my students will win.

If possible, please use the real thing to test your software as soon as possible. Use simulators only in certain timing tests. Without an actual test unit, your project is doomed. Don’t even think that you can know everything what comes on the real testing.
The on-line programming connector is available. It was need during the first tests. The good and reasonable priced programmer is PICKIT2 from Microchip. A newer replacement for PIC16F877A is PIC16F887. Is now recommended by Microchip instead of PIC16F877A. It has internal oscillator, but the provided HEX code is not suitable for this cpu without modifications.

The installation and testing

After the very first test the power supply was protected from voltage drop during the start with diode and 1000uF. Some small modifications were done into code like manual mode for easier testing in the test circuit. The device worked well after these modifications. Some years have elapsed, now is year 2007. There are bigger and more expensive CPUs available, like PIC18F-, PIC24- and PIC33-series. I have tried also ARM7 series, but returned to Microchip. They are more practically oriented for interfacing the real time devices.
Later I build more sophisticated auto robots for horserace and Off-Road Robot Competitions. I have used a LCD and four keys with menu selection for human interface. However, I must admit those eight keys, eight push buttons and eight potentiometers are much more elegant solutions than four buttons and menu. I must remember to use a KISS method (Keep it Simple Stupid) next time.

Picture 2: The acceleration robot installed in BS-03 Velociraptor

The Servo

Kuva11.jpg

Picture 3 the mechanical connection of the servo to carburettor.

Kuva13.jpg

Picture 4. A power servo HS-625MG

The servo must be powerful and fast. We used a HITECH HS-625MG servo. See the picture 4. It has three metal gears and one plastic gear and a dual ball bearing is the main gear. At 6V it has following specifications:
0.15sec/60 degrees
6.8kg-cm (94.43 oz-in)
Length: 40.6mm (1.59")
Width: 19.8mm (0.77")
Height: 37.8mm (1.48")
Weight: 60g (2.11oz)
Well, we didn’t use it with six volts, but at 7.2V. We wanted to get extra power to drive the servo to the limits.
It has worked well. Of course it doesn’t work constantly, so don’t take our experience as granted. The wheel in the servo controls the throttle lever in the carburettor. See the picture 5.
The output of the servo bit is inverted and adjusted to 7.2V volt control level with a NPN-transistor.

Kuva14.jpg

PICTURE 5. BS-02 AND BS-03 (=fast thief) with the soul of ancient velociraptor

The final words

I have described a prototype project. All the need information is available others who want to build similar unit for their favourite motor sport competition.
Please look carefully software part of the article. I believe that you can learn how you can solve your next software project more easily. Read also the source code of the project. It is not so important as the basic principle of Tampere style. The hardware part is the most easily to understand.
If you want increase the mileage of your car, maybe you want build a similar thing. You can then rive your familiar routes as taught to the robot earlier and save the world.

Ref 1 Shell Eco Marathon http://www.shell.com/home/Framework?siteId=eco-marathon-en&FC2=/eco-marathon-en/html/iwgen/leftnavs/zzz_lhn3_0_0.html&FC3=/eco-marathon-en/html/iwgen/sem_news/sem_2007_nogaro_news.html

Ref 2 BS-Mielage team http://fmmc.kapsi.fi/BSMM/eng/index.html

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License