Monday, March 10, 2008

Update 3/10/2008:

I been MIA working on some paying projects. After I completed that, I got drawn into a new venture with a buddy. I can't say too much about what it'll be, but in order to get ready for it I've been playing with a new chip (to me anyway). The Atmel Tiny13.

Pros:
  • 8-pin dip $1.29
  • No xtal needed has internal clocks up to 9.6MHz
  • Supports in-circuit programming
  • 1K flash, .5k EEPROM
  • 6 I/O all of which can be digital or 10-bit A2D
  • Requires a pull-up on reset
  • Uses the same GCC compiler as I am used to
Cons:
  • Internal clocks while they can be calibrated are somewhat inaccurate (thought they work fine for what I want)
  • 1K of flash goes fast :)
In a nutshell I wanted a servo tester/driver. So I surfed the web, found snippets of code here and there, and came up with a little demo. If I were to use this on my robot, I would change it to trigger a "pickup" sequence of servo moves. However, I've never really played with the A2D on an Atmel and I purchased 4 Sharp gp2d12's so I figured why not. The A2D is read about 40Hz which is also how often the servos get a new value (if required). The timer ISR is set to execute every 13us. At the end of every 20ms frame, the servo signals are turned on. Each run of the 13us timer subtracts 1 from the servo count until it reaches 0. Then the servo pin is turned off. I'm only using the upper 8-bits of the A2D conversion (16-bits adds a lot to the program size and I don't think it's needed). The most current reading is compared to the previous reading + or - 7. This is to prevent the servo from "jerking" all over the place, but it results in visible "stops" in the video.


Here is a video of the results. I may add to it, I may not. The important thing is that on a 1" square PCB I can have a multi servo controller that uses analog feedback to position the servos.

I promise to post the source code once I get it cleaned up (this was just quick and dirty) and commented.

Forward,
Jay

Monday, January 21, 2008

Progress 1/21/2008

While I should be working on a different project I worked on my robotic gripper design today. I have posted video of prototypes 2 and 3.





Jay

Wednesday, January 02, 2008

I'm still here, just recovering from the Holidays. My plans to use an RTOS have proved to be too much work and not enough progress so I am going back to my interactive code. At this point my robot is still and R&D tool for me to test my code for a specific purpose so I don't actually need concurrent threads of behaviors.

My next little project is to code to control my 2-DOF gripper. What's that you say, you didn't see any posts about my updated gripper. I'll post some photos soon. The code shouldn't be difficult using the AVRLib library though.

Jay

Friday, November 30, 2007

One step forward, two steps back:

Well I shot myself in the foot so to speak. I took my code to work to hammer out some of the details. This meant a lot of changes without being able to test them. Somehow I incorporated old code into the new code and contaminated both :(

Long story short, I'm going back to a reliable backup on 11/25/2007 which was before my last two posts. Thus, I'm progressing in the wrong direction. The good news it, I'm incorporating the code optimizations I made recently into the old code prior to me breaking out the functions into their own files. This way I can know they work before I change too many things at once.

On a good note, I've been mocking up a claw mechanism at lunch today. Saw a YouTube video of one I liked and fashioned a working model out of craft sticks.

Jay

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

Monday, November 26, 2007

Video of new code. Here is a short video of the robot now. The 4 commands I set are:
go 5 5
go -10 3
go 0 0
go 0 1

Friday, November 23, 2007

Updates for 11/23/2007

My code to command the robot to go x distance or turn x degrees works great .. .the issue is that due to slight differences in the motor speeds, the robot could be off by as much as an inch in a 2 foot span. So I decided to change the system over to a target based one.

The code is inspired/copied from David P Anderson's find_target and odometry code. I did add some tweaks of my own, and I've not yet started on using an RTOS.

I added a function that allows me to specify a target coordinate (x,y). Then I added find_target to my timer loop and call it every 30ms. The function looks at the distance and angle and commands the motors to those speeds. By using he distance left to set the speed I get nice fast and crisp movements. Before I added/fixed the code that your set the speeds proportionally, the robot was all over the map oscillating like crazy. Have a look at tonight's results.

The robot starts at 0,0. I then commanded it to go to 5,5 (that in inches BTW) and then to go to -10, 3. The pink and yellow lines are there for reference. The blue line is the plot of the X and Y coordinates reported by the robot. I have the printout function send data every 40ms (a bit too fast really) so the point markers are really close.



To dos:
1. Add the ability to create a point array from the drive pattern routine. Then have the robot traverse the array.
2. Figure out how to call the print routine every X ms. Because it uses an interrupt, it'll have to be outside the timer routine that I use for the PID and find_target.
3. Find a suitable and ready to go RTOS to port my code to. I'd rather quit fooling with ms timers and just run all the processes concurrently and have a central function call each when it's their turn.

Onward,
Jay

Saturday, October 13, 2007

Lots of discoveries tonight!

Man what a day. I worked with the students today on getting the TIMER basics down, configuring their development platforms (WinAVR, AVR Studio, JTAG ICE), and learning how useful Excel is for calculating TIMER registers.

During all the back and forth, I had an epiphany. I was using code that limited my PID adjustment to +-100 (as in percent). I was using 10-bit PWM, but by limiting myself to (let's just look at forward speed) 100 possible values (out of 1024 (2^10)). Well that's still not totally true either. I'm using locked anti-phase PWM so only values above 512 generate forward motion. But I digress, I'm still only using 1/5 of the total values I could. So I modified my code and changed the limits to +-511. It works, and a lot better. Still need to tune the PID constants, but things are a lot smoother.

On a bad/disappointing note I ran my Lipo to 12.8V. Minimum is 12V (3V per cell) but I decided to check (for the first time since I had it) the individual cell voltages. Bad news:
  • cell 1 - 2.9V
  • cell 2 - 3.49V
  • cell 3 -3.02V
  • cell 4 - 3.34V
Wow, not good. My charger wouldn't even attempt to charge cell 1. Lipo charges are constant current, constant voltage chargers. I have a pretty sophisticated NiMh/NiCD/Pb charger. I set it for 2 NiMH and the charge current to .1A. I connected my DMM and monitored the voltage until it was 3.2V. Now the Lipo charger is charger that cell first. Only 3 more to go. Oh well, better than having to replace the pack.I'm not drawing huge currents or this could have been a lot worse.

From now on, I'm going to check balance every time.

Jay

Thursday, October 11, 2007

Video

As promised. A short video of my bot in action. The video starts with me showing the pattern function. I told it to drive a pattern with 5 vertices and sides that are 20" long. At this point I fix the speed at a mild rate. After the pattern completes I instruct it to drive 24" at full speed. You can really see the left steer. Then I instruct the bot to turn 360 degrees full speed.


Jay
Progress!

Last night I was able to connect to my robot, send commands, and receive output. This is huge (to me at least). Next step is to modify the receive code to parse out the data into arrays. Then to plot them. To do this, I will create a JPanel class that I can override the paintComponent function to do my bidding.

This weekend is a bachelor weekend so I hope to have it mapping by Sunday. At which time I'll do a video ... finally.



Onward,
Jay