Marriage of orange detector with map formation successful.
One of the jewels of driShTi (our B.E. bot) was a red/orange detector (stupidly called orange filter by Gowri!!)
I tied it up with my obstacle detector (as of today red plastic cups!!) and now we are able to estimate distance and positions of these cups from the camera to the acuracy of a centimeter!! (Yeah, the calibration is on its way and soon i wont have to feed one dimension of the cups!).
Map and navigation
I got the force field algorithm up and running which would take the map with obstacles and target and form the force field.
Fight with serial port.
What should happen when you are desperatly trying to combine vision with motor commands? Well, the serial port program should expire….
| Gyan: Dont rely on something you got for free to stay, especially when its not a simple thing! |
Like it happens quite often, I was in the lab I TA and Rohith with bot. Like cricket fans hate to miss even a single ball of the game, I hated to not be with bot. So I would log in from the lab and in the few minutes I didnt have students asking me I would try to get updates. Rohith almost screams through the text that our serial port code which we had downloaded has expired.
Now what?….well, what else….there is no escaping - write it on our own using what the OS has to offer.
So I do a start up google search and get a place where there is small tutor on how to use windows APIs to communicate.
Laptops have no serial port- so i cant try my code and Rohith burnt out with serial has started work on vision aspects.
After a couple of hours, when I could return to our lab we try this API stuff and lo! it works!
| Gyan: If one idiot can do it, so can another! |
PWM Control
One important task to be done before navigation was controlling differential speed of two motors. If both the motors rotate at the same speed, the robot moves straight. If we want the robot to turn, one of the wheels should turn slower than the other. To achieve different types of turnings, we should be able to vary the speed of each motor in degrees, thus moving the robot along circles of different radii.
Since the motors could just be turned ON and OFF, we had to achieve speed control through Pulse Width Modulation. We made a buffer of 100 characters, which we call a frame. At beginning of each frame would be two commands which would start the two motors. Depending on the turning radius, somewhere in the rest of the frame would be two commands which would stop the motors. Ex: If the robot has to turn left, the left motor's stop command would come earlier in the frame and the right motor's stop command would come at the end of the frame.
Although PWM does not give linear response over rpm, it gives us sufficient control over the speed to turn the robot. We want to put a look-up table to solve the linearity problem.
The great merger
With code torn between the laptops we had to merge it so that vision and motor action come together.
With some good and some bad programming styles we managed to bring together the mind, brain and the neurology of Samprajna for the first time!
Fight with multithreaded.
When have we ever stopped at "good" results?? Move to "better" is our way!
So this great plan of trying to put all the pieces together in a multithreaded program - with vision as one thread, filling of the command buffer as another and talk to serial port as another.
We try and we try…and we try…everything seems fine but why wouldnt the bot stop???
Well, may be the threads are interleaved too badly (i was too lazy to use formal synchronization…so had used shared variables!)
May be this….may be that.
Finally, we had nothing left to blame in the threads section!
So what do we do? Well, obvious…ditch it. Turn threads into functions and call them when ready.
Did that help? Well……no.
Now this is tooo much for anyone….only option is to debug old style.
Then it comes…a great brainwave : How is the serial port getting to know what is in the "memory chunk" is not updated?
Then it all falls in place….the buffer wasnt flushed out and it would keep reading the last command!!!
Then we decide to see MSDN and realize we must explicitly flush the buffer each time! just another line of code!
| Gyan: If something looks perfect and yet something is wrong….then you are wrong! |
Success always comes at the end of the day!
Does success like only end of days? or end of day comes as soon as we have success?
Whatever be the case, just as it was about time for us to go home we managed to tie all the loose ends and see it go according to what it sees (though some of it wasnt "supposed" to have seen!)





