Zumo shield and Servos

The place to discuss the Pololu 3pi, m3pi, and Zumo robots and share your code.

Zumo shield and Servos

Postby patman715 » Fri Apr 11, 2014 9:22 pm

Is it possible to use the Zumo shield to still control the motors AND operate a couple servos? Maybe modify the servo.h library for my Uno? Put the motors on some other pins than 9 and10? Maybe I should just by a Leonardo? Would that fit on Zumo shield? Im new with so many questions. Thanks
patman715
 
Posts: 8
Joined: Fri Apr 11, 2014 9:11 pm

Re: Zumo shield and Servos

Postby jwatte » Sat Apr 12, 2014 10:48 am

The Servo library on modern Arduinos does not require any particular pins for servos. It can drive any pins for servo control signals.
The main question I would have would be how you get sufficient power to the servos.
User avatar
jwatte
 
Posts: 300
Joined: Tue May 15, 2012 6:56 pm

Re: Zumo shield and Servos

Postby patman715 » Sat Apr 12, 2014 4:50 pm

I thought there was a conflict with Servo.h library and pins 9 and 10 of the Zumo motos? I am mounting a gripper to the Zumo shield. It uses two servos. It will use the Sharp distance sensor to run around and grab stuff. I tried several times to post a jpg picture but it always says invalid file format?? Servo power will just come from the battery pack directly to the center pin or red power plug on servos. Of course the grounds all have to be tied together, one going to Arduino board. I learned that lesson.
I guess my question is how to program the two servos and still use zumo motor library. Thanks!
patman715
 
Posts: 8
Joined: Fri Apr 11, 2014 9:11 pm

Re: Zumo shield and Servos

Postby jwatte » Sat Apr 12, 2014 10:06 pm

I see what you're getting at. Pins 9 and 10 use Timer 1 (the 16-bit timer) if you want to do PWM, so the Zumo support library takes over timer 1. Which Servo.h also does.
If you drive pins 9 and 10 only using digital write (full or nothing,) then you can use the Servo.h library (and not use the Zumo support library.)

If you want to generate servo control pulses manually, you *can* do this with a busy-wait poll loop. However, you can't do anything else while doing this, which may or may not be OK for you. You can drive multiple pins in parallel this way, too, with a bit of software panache.

Example:

Code: Select all Expand


This will jitter a little bit because of the interrupt handlers in the Arduino support library. Thus, you can disable interrupts before this code, and enable interrupts after it, for better timing.

If you want to run multiple pins at the same time, you're probably better off addressing them directly with PORTB or PORTD or whatever:

Code: Select all Expand


This will turn on pins 8, 9, and 12, and turn off pin 12 after 1200 microseconds and pins 8 and 9 after 1400 microseconds (give or take a little bit.)
User avatar
jwatte
 
Posts: 300
Joined: Tue May 15, 2012 6:56 pm

Re: Zumo shield and Servos

Postby kevin » Mon Apr 14, 2014 5:40 pm

Hi, patman715.

We have some information on controlling a servo with a Zumo-mounted Arduino in the Zumo shield user's guide. We have some example code for controlling a single servo using Timer 2 on the Uno, but that might not work for you if you need to control more than one. It's easy to modify the Leonardo's Servo library to use Timer 3 instead of Timer 1, so I'd suggest trying that approach.

- Kevin
User avatar
kevin
Pololu Employee
 
Posts: 588
Joined: Thu Oct 14, 2010 5:22 pm
Location: Las Vegas, NV

Re: Zumo shield and Servos

Postby patman715 » Mon Apr 14, 2014 5:53 pm

The "delayMicroseconds(1750)" command then acts similiar to the library in that 1500 or 1750us would center the servo? And 0 would reverse it to one end of the range and say 2500 or depending on the servo, the other end of rotation? Stopping or pausing here in the loop should be no problem. I appreciate your help.

Kevin thanks. I assume then a Leonardo will fit on Zumo shield and I wont lose the cool buzzer sounds then. The Sharp distance sensor chirps a signal frequency according to the distance voltage creating a cool sound based on how far away object is.
Just placed my order for Leonardo and looked over 8.1a and b again. Ive never created a library but maybe I should modify servo.h and call it servo2.h? Then #include servo2.h IDE doesnt allow editing .h files, does it?
Last edited by patman715 on Mon Apr 14, 2014 7:23 pm, edited 1 time in total.
patman715
 
Posts: 8
Joined: Fri Apr 11, 2014 9:11 pm

Re: Zumo shield and Servos

Postby kevin » Mon Apr 14, 2014 7:12 pm

Our libraries use the Leonardo's Timer 4 to drive the buzzer, so I think you should be able to do everything you want at once (motors, servos, and buzzer).

- Kevin
User avatar
kevin
Pololu Employee
 
Posts: 588
Joined: Thu Oct 14, 2010 5:22 pm
Location: Las Vegas, NV

Re: Zumo shield and Servos

Postby jwatte » Tue Apr 15, 2014 8:53 am

The "delayMicroseconds(1750)" command then acts similiar to the library in that 1500 or 1750us would center the servo?


Yes, 1500 centers the servo, 1000 goes 45 degrees one way; 2000 goes 45 degrees the other way. If it's a 180 degree servo, the range expands to 500...2500

If you can use a Leonardo with a modified library, that's probably even simpler, though :-)
User avatar
jwatte
 
Posts: 300
Joined: Tue May 15, 2012 6:56 pm

Re: Zumo shield and Servos

Postby patman715 » Tue Apr 29, 2014 6:57 pm

P_20140421_083819.jpg
Zumo with servo grpper
P_20140421_083819.jpg (156.86 KiB) Viewed 1257 times

It is SO Cool it works!
patman715
 
Posts: 8
Joined: Fri Apr 11, 2014 9:11 pm

Re: Zumo shield and Servos

Postby kevin » Wed Apr 30, 2014 11:57 am

That looks fun! Do you have any videos of it in action?

- Kevin
User avatar
kevin
Pololu Employee
 
Posts: 588
Joined: Thu Oct 14, 2010 5:22 pm
Location: Las Vegas, NV

Re: Zumo shield and Servos

Postby patman715 » Wed Apr 30, 2014 4:36 pm

Zumo grabber: http://youtu.be/w-1GWoCI3GU

Can I upload mp4 directly here?
patman715
 
Posts: 8
Joined: Fri Apr 11, 2014 9:11 pm

Re: Zumo shield and Servos

Postby JonathanKosh » Thu May 01, 2014 5:34 pm

Hi.

Cool robot! We would like to add your project to our community blog posts. Have you posted a write-up about it somewhere? If not, we would be interested to know if you used anything else from us.

I do not think you can upload .mp4 files to our forum; is there a reason you want to do so? Since the video is uploaded to YouTube, you could just embed it in a post.

-Jon
User avatar
JonathanKosh
Pololu Employee
 
Posts: 398
Joined: Mon Jun 04, 2012 10:00 am
Location: Las Vegas, NV


Return to 3pi, m3pi, and Zumo Robots

Who is online

Users browsing this forum: No registered users and 2 guests