Servo Code!

Show off your projects to others!
sierrasmith71
Posts: 34
Joined: Mon May 23, 2011 7:22 pm

Re: Servo Code!

Post by sierrasmith71 » Mon Sep 19, 2011 4:08 pm

I am using the ITDB02 from ITead which is a 3.2" display and Henning Karlson's library:

See: http://chipkit.org/forum/viewtopic.php? ... t=10#p1131



Best Regards

David G.

Bypeduredads
Posts: 6
Joined: Mon Dec 05, 2011 7:53 am
Location: Austria
Contact:

Servo Code

Post by Bypeduredads » Tue Dec 06, 2011 2:42 pm

As you have already experienced, there is no data-sheet available for above servo motors. Below posted is a simple code that you can use for getting an idea about the pulse width of the servo.


Code:

dragonbot
Posts: 7
Joined: Wed Sep 26, 2012 8:16 pm

Re: VarSpeedServo -unqualified-id before numeric constant

Post by dragonbot » Thu Oct 25, 2012 5:41 pm

Hi guys,

In reference to library VarSpeedServoPIC32 posted by davec in this thread, I have been beating my head on this for last 2 days and can't a simple code to work, though the following works just fine on the Arduino.
I have even tried to change all references of "BYTE" to "uint8_t" in VarSpeedServo.cpp

I am running mpide-0023-windows-20120903
so a lot of the library issues noted back in 2011 seem to be already fixed in this version of the IDE.

Could someone please help before I go nuts or resort to the inferior Arduino which I vowed to stay away from.

Code: Select all

#include <VarSpeedServo.h>

const int NBR_SERVOS = 4;       // the number of servos

VarSpeedServo Servos[NBR_SERVOS];        // servo objects


int servoPins[NBR_SERVOS]        = {8,     9,  10,  11}; // servo pins
int servoSpeeds[NBR_SERVOS]      = {1,    10, 100, 255}; // sweep speed, 1 is slowest, 255 fastest)
int servoMinPosition[NBR_SERVOS] = {10,   20,  30,  40}; // the minumum servo angle
int servoMaxPosition[NBR_SERVOS] = {120, 130, 140, 150}; // the maximum servo angle

void setup()
{
   for(int i=0; i < NBR_SERVOS; i++)  
   {
     Servos[i].attach(servoPins[i]);       
     Servos[i].slowmove(servoMinPosition[i],servoSpeeds[i]) ; // start sweeping from min position
   }
}

void loop()
{
  // sweep the servos
  for(int i=0; i < NBR_SERVOS; i++)
  {    
     if( Servos[i].read() == servoMinPosition[i])
       Servos[i].slowmove(servoMaxPosition[i],servoSpeeds[i]) ;         
     else if( Servos[i].read() == servoMaxPosition[i])
       Servos[i].slowmove(servoMinPosition[i],servoSpeeds[i]) ;           
  }  
}

Code: Select all

Error:
In file included from c:\mpide-0023-windows-20120903\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/peripheral/i2c.h:50:0,
                 from c:\mpide-0023-windows-20120903\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/plib.h:54,
                 from C:\mpide-0023-windows-20120903\.\hardware\pic32\libraries\VarSpeedServoPIC32\utility/int.h:39,
                 from C:\mpide-0023-windows-20120903\.\hardware\pic32\libraries\VarSpeedServoPIC32\VarSpeedServo.cpp:62:
c:\mpide-0023-windows-20120903\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/GenericTypeDefs.h:342:33: error: expected unqualified-id before numeric constant
c:\mpide-0023-windows-20120903\hardware\pic32\compiler\pic32-tools\bin\../lib/gcc/pic32mx/4.5.1/../../../../pic32mx/include/GenericTypeDefs.h:360:5: error: expected unqualified-id before numeric constant
Last edited by dragonbot on Thu Oct 25, 2012 10:40 pm, edited 2 times in total.

EmbeddedMan
Posts: 602
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: Servo Code!

Post by EmbeddedMan » Thu Oct 25, 2012 6:57 pm

Just a guess, but do you know if there is any AVR specific stuff in VarSpeedServo? This is not a standard (i.e. included) library with Arduino or MPIDE. There may be some things that need to get changed a little bit so it will work with the chipKIT boards.

*Brian

dragonbot
Posts: 7
Joined: Wed Sep 26, 2012 8:16 pm

Re: Servo Code!

Post by dragonbot » Thu Oct 25, 2012 8:06 pm

EmbeddedMan wrote:Just a guess, but do you know if there is any AVR specific stuff in VarSpeedServo? This is not a standard (i.e. included) library with Arduino or MPIDE. There may be some things that need to get changed a little bit so it will work with the chipKIT boards.

Could be. But I assume this was already worked out by poster "davec" who posted VarSpeedServoPIC32 library further up in this thread. :
http://www.chipkit.org/forum/viewtopic. ... 0&start=20

davec
Posts: 30
Joined: Tue Jun 28, 2011 1:04 pm

Re: Servo Code!

Post by davec » Fri Oct 26, 2012 12:51 am

Yes they reshuffled the include files slightly. The attached version compiles OK , I haven't tested it though.

Edit: I re-attached this file as it was corrupted in the forum storage.
Attachments
VarSpeedServo_mpide_0023.zip
(10.75 KiB) Downloaded 35 times
Last edited by davec on Sat Apr 11, 2015 10:15 pm, edited 1 time in total.

KurtE
Posts: 64
Joined: Wed Nov 16, 2011 11:24 pm

Re: Servo Code!

Post by KurtE » Fri Oct 26, 2012 3:16 pm

Not sure if any one is interested, but I also hacked up the Servo Library (like I did on the Arduino) and created a new private library (servoEx), which has code on the interrupt handlers to update the positions per pulse, such that you can have timed moves, or a group of servos with a timed move... At some point soon, I will try it out on one of my Hex robots and see if I can get the servo library to work with 18 servos without any jitters...

I do have a test in my test app, that shows that it is at least working for one servo at a time... Where I have it sweeping the servo back and forth from 60 to 120 degrees, with code that looks like:

Code: Select all

for(;;) {
    if (!g_servo.moving()) {
      fServoDir = !fServoDir;
      g_servo.move(fServoDir ? 120 : 60, 500);
    }
}
This code tells it to move to 60 or 120 degrees and take 500ms to get there and I have a test (moving) as part of the library that says has the servo made it to it's destination or not... Note: in my actual code I have more than the actual for(;;;) loop

Kurt

dragonbot
Posts: 7
Joined: Wed Sep 26, 2012 8:16 pm

Re: Servo Code!

Post by dragonbot » Fri Oct 26, 2012 4:18 pm

davec wrote:Yes they reshuffled the include files slightly. The attached version compiles OK , I haven't tested it though.
Hi Davec
That worked !!! yay !!
I should have just pinged you before instead of beating my head on this for a whole day and a half. YOU DA MAN !!!

dragonbot (Bruce)

bcrepet
Posts: 1
Joined: Wed Dec 24, 2014 3:14 pm

Re: Servo Code!

Post by bcrepet » Wed Dec 24, 2014 3:32 pm

Hello,

I uploaded the VarSpeedServo_mpide file but I have problem to unzip the file no matter how I try to (with 7-ZIP and Winzip and on 2 differents computers).

Is there something special to do to make the file usable?

Thanks

davec
Posts: 30
Joined: Tue Jun 28, 2011 1:04 pm

Re: Servo Code!

Post by davec » Sat Apr 11, 2015 10:17 pm

Hi bcrepet, I re-attached the file to the original message, you should be able to download it now.

Post Reply