Wednesday, November 28, 2007

Updates 11/28/2007:

I have successfully added RTOS (real time operating system) to my code. I'm using FreeRTOS (www.freertos.org) and it was relatively painless to incorporate. Some of the details that slowed me down:
  • The kernel timer uses Output Compare 1A which is the same I was using for the right motor PWM.
  • The port.c file configures the Timer 1 only for Output Compare 1A which overwrites all my settings for pwm I set in my motorInit code. As such, I changed the code in port.c to use |= when setting it's bits. This is the only kernel change I had to make.
  • I used to have all my code in one file. This is due to the fact that I just kept adding on to experimental code rather than formalize everything. Prior to the addition of the RTOS, I broke out functions in to separate files based on organization (motors, motion, and eventually sensors).
  • I was also using a lot of global variables (bad form I know but it's been fixed) in my one file. Rather than declare them extern in my new files (yes I tried that at first), I added functions to "get" and "set" key variables.
The benefits of this rework?
  • Now I can add a task to the list to execute without other functions having to call it or be aware.
  • No blocking (well except for serial, but it's the lowest priority) so now pauses (which used to nop for x milliseconds) just yield to other processes.
  • Now I can build behaviors that can layer on top of each other and turn them on or off via a monitor/command line program.
  • Sensors will run in their own task loops (like sonar) at set intervals which was more difficult to time with function calls especially when something new was added to the mix.
All in all I'm very pleased with this decision and I know it'll pay bigger dividends as my experimentation increases.

To do:
  • Wire up the 4 IRPD sensors and 2 bump switches.
  • Code a wall following behavior
  • Code a avoid behavior (to drive/navigate) around an obstacle while still trying to get to a target coordinate :)
Other updates:
  • I ordered a Lipo balancer for my battery. I got a great deal on the battery I use (4S 12C 33oomAH) and the replacement cost would be much more than I paid (thank you www.cheapbatterypacks.com) so I'm going to baby this one.
  • Through typos I ran my motors full speed using the new RTOS code. The measured speeds were 90 ticks/ 20ms. The movie below shows the motors going 18 ticks/20ms so I plan to increase the max speed a bit. For shorter runs the code will auto slow the bot anyway, but this make longer distance "shorter" ;)

Jay