Over the weekend, particularly on Saturday i was spending quite some time in the grand hall of UiTM Shah Alam. The architecture and interior of the building was spectacular and it was nothing like the hall or auditorium we have at Sunway. The tiered layout and curved nature of the building made it have this very interesting layout. Well, i wasn’t there to enjoy the brilliance of public tertiary institutions. I was there to compete in the Freescale Cup. In case you don’t know what the Freescale Cup is, i did a writeup about it a few weeks back and you can check that here. In short, it’s a competition which combines the idea of programming with a hint of physics/mathematics to create an algorithm to run the race car around the given track.
Initially, i was planning to do a weekly log article on the progress of the competition but then i was just stuck. I did have the intention of writing all about my interesting findings about how the car is supposed to set up. But the problem was that most of the time i was very unsure about the situation and i wouldn’t want to mislead others into thinking what i did was right so ultimately i didn’t do it.
First off, a little prelude of how i got to this day. I won’t lie, this competition was not easy for anyone on the team. From our minute knowledge about embedded systems to not so professional technical skill, we had a lot to learn in order to get the car up an running. At the start it was always the three of us in the picture during meetups but soon enough, each of us had our own activities to do about and after the first month our communication frequently happened on facebook.
I was interested in learning it so i ended up working with the car quite frequently. Throughout the weeks, i mostly messed around with the hardware configuration and touched little but not much of actual code to run on the microcontroller. Also, getting the hardware ready was one thing but hunting down for the charger to charge the battery was quite something. In the end i just ended up borrowing the power supply from the lab.
But even then, charging the battery was also a learning curve, i first tried dialing up the voltage to the battery’s 7.2v but that clearly didn’t work out as the battery didn’t gain any charge whatsoever. Soon enough, i came to realize via a couple of youtube videos that the voltage has no effect when charging the battery, the current is what charges the battery.
Along the way i also learnt that the two poles of an NiMH battery or any sort of live wires should never cross each other as it’ll cause a spark or as i like to call it a ‘light show’
Programming the Freedom Board
Once the battery problem was solved, the next thing was to try loading some code onto the board and see what does what. It was really a pain in the ass as i was unable to even debug the code onto the board. But eventually after some time, the code did work and i was happily playing with the hardware components of the board especially the motors. Turning it up to high speed has it’s wonder.
That pretty much lasted throughout the 2 months of prep time we had and not until the last two weeks where i actually started to dive into the inner workings of what makes the car follow the black lines on the track. It was real hard, debugging on the IDE’s console can be quite complicated at times but with a connected hardware brings coding to a whole new level.
Often times, the compilation doesn’t push out any error messages of any sort but somehow the hardware on the board isn’t reacting to the code. For countless times, i just ended up giving up on hope that i’ll actually get the hardware running with my own code. Realistically, till today none of my code actually works on the board with the exception of the code for the LEDs and the onboard motors. I just can’t seem to get the linescan camera and servos working.
Cracking the algorithm
While i failed activating the hardware on the car to work with my code, ultimately i ended up googling some sample code. When i found a solid code which worked, i was over the moon. But little did i know that the sample code published was actually using the older track which followed a single line.
The new edge line track featured two black lines on either sides of the tracked and that posed a major problem. For the last week leading up to the competition, i was racking my brains on how to modify the algorithm to make it follow a two separate lines. Not until the 2nd night before the competition day did i think of an ingenious solution to solving the said problem by modifying the already available algorithm.
I had the idea of how to solve the issue and implementing it was not the problem too but somehow the logic was a little off as the camera somewhat only reacted to certain black lines. I did went through the logic of things and i could not find out what was actually going on and in the end, that very code with a slight modification was the one running on the car on the competition day.
The actual competition
As i mentioned earlier, the competition this year was held in UiTM Shah Alam and the venue was quite grand. As usual, i was there real early and i had gotten myself a pretty sweet parking spot just outside the hall. Somehow, i forgot to wear a pair of long pants and i was the odd one out in the entire competition wearing shorts and slippers. It was a cold and brutal day.
The agenda of the day was clearly stated but somehow the timings were a little off but that could be because of the record turnout this year. There were 65 teams representing nearly 40 tertiary institutions throughout Malaysia. The day started with a registration which includes drawing the sequence in which we’ll compete and also to collect our ‘participants’ tag which did not feature a generic name.We were also given coupons for breakfast and lunch.
By the time we were seated on our designated table, the time was about 9am and so i started off with the final preparation for the car’s code. So, for the next 2 hours, the four of us was discussing about the problems that might lie within my solution. That ended up with a lot of confusion, even for me with my own code.
Two hours quickly passed by and by the time we were about to trace the program, there was only 30 minutes left. The first thing we did during that time was to kindly lend a charger from our friendly neighboring table to the left and thankfully they had the heart to help charge our battery. We were supposed to surrender our car to the judges by 11 and in the end we submitted the code which had been slightly modified and the rest was all on luck.
The waiting games
After placing our car on the judging table, it was all about waiting for the hour(s) to pass by before our car gets judged. So, while waiting, i managed to take quite a number of photos of our car and also some interesting designs i came upon. After like about 20 minutes of staring at all the cool and baller designs which we could’ve implemented. The 4 of us was happily seated on the table. Soon enough we felt restless given the fact that there was no wi-fi connection there and also 3G is pretty poor in the hall.
While also waiting for lunch to be served, we then started talking about lots of random topics. I think it first started with recommendations to improve the program and then it morphed into just about any topic we could think of. One of the highlights was this book called 5 love languages which teaches couples how important communication is to retaining a relationship. Do check out the website, you can learn something new with it.
At about 12:50-ish our car was finally judged and then it was off to lunch before the race happened at 2. Surprisingly, the food was pretty good. I think it was a indian fusion food as there were indian spices with the traditional malay food. Overall it was quite some good stuff.
Racing around the track?
Lunch was good and shortly after that, the race around the track finally started. The first few teams suffered from the ‘car go out of the track’ syndrome. I was initially quite worried that our car was the only one to not work but after watching a few teams compete on the track, i felt a little relived. I think after the 9th team, i was quite tired of watching already and i went back to the table to sit down.
What’s the procedure for each team? Each team will be given three attempts to complete 1 lap and the best time will be selected. In addition to that, each team is also given 2 minutes to try out their car around any part of the track. And only one team member will represent the team in the race track at any given time.
For the next two hours the 4 of use continued talking about just about anything that comes to mind. Our turn to race around the track came about 4pm and damn was i nervous to actually run the car through the track. As expected, the car didn’t manage to run through not even the first part of the track. I was already quite intent that at least the servos did slightly bunk to the right when it saw the curve but overall it was quite ok.
This is about it for what happened on that day, oh we were also given certificates and a pretty cool race car shaped flash drive to commemorate the time we spent there. I would say that everything happened for a reason as a few days before, i actually had the mindset not to go to the competition because the code was basically not working at all. But luckily, i came to my senses that i’ve been working on this for such a long time and not trying it out on the actual race track would’ve been a complete waste.
— dickwyn (@dickwyn) May 23, 2015
I wouldn’t count this as a complete failure, although our car didn’t even manage to pass the first curve without slipping out of the track, there was a sense of relief when i saw it go out of the track. True, to others it might’ve looked like i wasted 2 months cracking up a car which couldn’t even make a turn but to me it’s quite an “accomplishment”.
The journey of fixing up the hardware to optimizing how the microcontroller board taught me an important lesson. That is to never give up as hope is always just around the corner. The coding part in the other hand made me realize that programming can actually be very very complicated and full of mathematical calculations.
It is clear that in order to even complete a single lap around the track, you’ll need to possess some level of skills in programming and so my advice to potential Freescale Cup participants that don’t give up when your car doesn’t follow the line, keep on trying and you might just be able to pull it off.
That is about this, this competition is probably one of the highlights of my life. Probably the first time i’m doing something like that and it won’t be the last. Maybe when i end up getting a degree in a couple of years time, i’ll try to fix up an autonomous car using the Freedom platform.
Until the next time!