Author Topic: iRobot Create Mod project  (Read 2037 times)

0 Members and 1 Guest are viewing this topic.

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
iRobot Create Mod project
« on: August 26, 2010, 09:46:25 AM »
Hi all,

To test out some hardware on my iRobot Create, I hooked up a servo to the command module via an iRobot breakout board (I'm pretty sure all the wires are connected to the proper pins, etc) .  I downloaded Admin's iRobot create mod project, and the servo isn't moving at all!!  I thought there was a fault in my code, but even Admin's isnt working.  I tested the servo with a controller, so I know its not defective.  I used an oscilloscope to check the signal, and it turns out that the pulses are not square pulses and the voltage is too high-- even though its connected to Vcc regulated 5V.  Any ideas on why this is happening?  Thanks is advance!

~RobotFreak

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: iRobot Create Mod project
« Reply #1 on: August 26, 2010, 09:59:03 AM »
Not square pulses? What shape are they? IO pins can only ever be on or off, so anything but a square shape is bad.

That worries me. Could be a fried IO pin on the Command module. Try using another pin, and test it first with an o-scope before connecting a servo to it.

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: iRobot Create Mod project
« Reply #2 on: August 26, 2010, 01:36:19 PM »
Thanks for the prompt reply. 

I changed the code to send the pulses through a different pin (heck, a different port altogether, just to make sure)....Stuck in the oscilloscope, and I'm still getting these weird triangular pulses with a peak.  I have absolutely no idea what's going on, I really need some help!

Thanks,
RobotFreak

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: iRobot Create Mod project
« Reply #3 on: August 26, 2010, 01:41:21 PM »
Post your code (even if its just admins modified code) so we can take a look.

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: iRobot Create Mod project
« Reply #4 on: August 26, 2010, 03:03:51 PM »
Here is the code.  (It is not the Admin's modified code, I modified the drive.c example program...)

Thanks, I really appreciate it.

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: iRobot Create Mod project
« Reply #5 on: August 26, 2010, 06:22:00 PM »
You are using delay functions to create a servo pulse. That's ok, but it wastes a lot of time that the processor could be doing something else, and tends to create servo jitter. When I programed my Irobot Create powered robot I used a hardware timer to create the servo pulse instead. It was much more precise, and let the command module worry about other stuff instead.

If you don't know how it works, watch the video on THis Page. Fast forward to about half way through.

But here's some of my code to help.

In the hardware pins section

Code: [Select]
  OCR1A = 46083; // sets PWM to repeat pulse every 20.0ms
  OCR1B = 3270;      //sets length of pulse
  TCCR1A = (1<<COM1B1) | (1<<WGM11) | (1<<WGM10);
  TCCR1B = (1<<WGM13) | (1<<WGM12) | (1<<CS11);
 

That sets up timer 1 to be used to generate a servo signal. To move the servo, change what OCR1B equals too. For our robot, 2520  to  4420  was the range of our servo.

And the pin your servo has to be connected to is PB1 I believe. Could be PB2 but I think it's PB1. (Using Arduinos and Webbotlib has made me lazy, and I forget which pins the timers flip now).

See if this fixes your problem, and report back.

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: iRobot Create Mod project
« Reply #6 on: August 27, 2010, 09:31:24 AM »
Hi madsci,

I took your code and pasted it exactly....still no movement.  What I don't understand is, even though using a timer may be a better technique, the servo should have atleasted moved when I was using the delayMs stuff.  My O-scope keeps giving me a triangular waves with a peak to peak voltage difference of 163 V!  I tested by servo with a controller that a I borrowed and it works fine, so I know that there is nothing wrong with the servo.  Do you have any idea what the problem is?  I'm really desperate, any help is greatly appreciated!

Thanks,
RobotFreak

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: iRobot Create Mod project
« Reply #7 on: August 27, 2010, 01:56:23 PM »
Hmm, this is odd.

Idiot check, but you do have the O-scope configured correctly (set to 10x probe if it's a 10x probe) and you are connecting the probe's ground reference to a ground pin from the Command module, right?

If you slow down your pulses to let's say 10 times a second (100ms delay) do you still get triangles?

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: iRobot Create Mod project
« Reply #8 on: August 30, 2010, 07:32:58 AM »
Ok, so when I went to check out the situation again before the weekend, it turns out that I finally got square pulses....in fact I didn't change anything, just gave it one last shot before I gave up, and it started to work.  My suspicion, like yours, is that perhaps I was using the O-Scope incorrectly.

This is the code that I'm using with the ATMega 168 chip timer for the servo:

 // Set up a PWM channel on Pin B1 (servo)
  TCCR1A = 0;
  ICR1 = 46079; // frequency is every 20ms
  //configure Timer1 for fast PWM mode vai ICR1 with pre-scaling of 8
  TCCR1A = (1 << WGM11);
  TCCR1B = (1 << WGM13) | (1 << WGM12) | (1 << CS11);
  // Set PB1 and PB2 as outputs
  DDRB |= _BV(1) |  _BV(2);
  TCCR1A |= 2 <<  6;  // enable PWM on port B1 in non-inverted compare mode 2
  TCCR1A |= 2 <<  4;  // enable PWM on port B2 in non-inverted compare mode 2
  OCR1A = ICR1 * 2 /20; // 2ms pulse to left motor on PB1

If I wanted to cycle through a few positions on the servo, could I use the numbers you provided in a previous post at pre-designated intervals in a for loop?  Also, for a different component, I need to have delays in Microseconds.  What would be the best way to accomplish this?

Thanks a lot!!
RobotFreak

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: iRobot Create Mod project
« Reply #9 on: August 30, 2010, 07:53:16 AM »
The numbers 2520  to  4420  where the 'ends' or extreme left and right of our servo. Our main loop would +/- 15 to those numbers (depending on direction of travel) to effectively have the servo constantly 'scanning' left and right.

You can either use a timer if you have any left; or use a delay_cycles() function and equate that to equivalent microseconds. I'll have to check my old Command Module code when i get back from work today, but I remember have a delay_cycles function.

Offline RobotFreakTopic starter

  • Jr. Member
  • **
  • Posts: 17
  • Helpful? 0
Re: iRobot Create Mod project
« Reply #10 on: August 30, 2010, 12:00:55 PM »
Please let me know, I'd like to understand what works best (or works at all) with the command module.

Stupid question: I understand the ATMega168 comes with only 2 timers....how would you identify or initialize a different timer? Simply change the names of the registers?  Sorry, I'm really quite new to all of this...

Thanks!

 


Get Your Ad Here