Pages: 1 2 [3] 4   Go Down
Author Topic: VarSpeedServo - a modified Servo library with speed control  (Read 16258 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just installed the library and referenced it. Upon build I get the following compile error. I use the latest Arduino 1.0 compiler running on Windows 2008 server with Arduino MEGA2560. Any thoughts?

Code:
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:56:23: error: WProgram.h: No such file or directory
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected `;' before 'channel'
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Program Files (x86)\arduino-1.0\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope

gives me the same error. Using 1.0.1 and installed it in right directory

*edit: replaced WProgram.h in the varspeedservo.cpp to Arduino.h
« Last Edit: November 24, 2012, 01:09:49 pm by hangtime21 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had the same problem with a Uno rev.3. Same solution. In VarSpeedServo.cpp, replace  #include <WProgram.h>  with  #include <Arduino.h> .
Logged

my own world
Offline Offline
Newbie
*
Karma: 0
Posts: 26
We are all geeks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've used the varspeedservo library in Arduino 1.0. I just changed WProgram.h to Arduino.h in one of the library files.

Thank you... I forgot about this little trick to get the libraries going with the 1.0+ IDE
I was beating my head for an hour,wondering what I am doing wrong,  before I read your post.
Logged

Signatures are stupid!

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am builduing a quadcopter with my arduino uno and using a bluetooth setup.  I just need help with this speed control.
Logged

my own world
Offline Offline
Newbie
*
Karma: 0
Posts: 26
We are all geeks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I seem to notice getting full range out of the servo seems tricky..
Maybe it is my hobby people servos but unless I put:


servo1.attach(5,555,180); this is the only way I can get 180 degrees.
but the speeds work fine.

I am trying to make a pan and tilt camera for on top of a rover.
Logged

Signatures are stupid!

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

I tried to apply also VarSpeedServo lib, but for some reason my code doesnt work. Whats wrong w/ it? Don´t mind the estonian comments between smiley.

Code:
#include <VarSpeedServo.h>
int BlueLed = 13;
VarSpeedServo servo1;  //Create a servo object

void setup() {
     // put your setup code here, to run once:
  servo1.attach(4); //Lisab servo PIN 1 servo objektile
   //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
   int speed = 10;
   int angle = 45;
   int angle2 = 0;
   int speed2 = 30;
   int sensorVal = digitalRead(2);
   //valjastab miskile registrile sensorVal sisu
   Serial.println(sensorVal);
   switch (sensorVal) {
     case LOW:
       servo1.slowmove(angle2, speed2);
       break;
     case HIGH:
       servo1.slowmove (angle, speed);
       break;
     }



Tnx in advance!
Logged

my own world
Offline Offline
Newbie
*
Karma: 0
Posts: 26
We are all geeks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not exactly sure, but where you have your servo1.attach (4);

your are going to need something like : servo1.attach (4, 0, 180);

4 is the pin you are attaching to
0 is the minimum rotation
180 is the maximum rotation

If  your problem is that you cannot get it to compile read earlier in this thread about
editing varspeedservo.cpp

replace WProgram.h in the varspeedservo.cpp to Arduino.h
Logged

Signatures are stupid!

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I replaced the attach with 0-180 degree limit and also overwrote inside VarSpeedServo.cpp lib include "WProgram.h" with "Arduino.h". But it still gives me errors. The error list is as follows:

Code:





C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In function 'void handle_interrupts(timer16_Sequence_t, volatile uint16_t*, volatile uint16_t*)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'LOW' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:91: error: 'digitalWrite' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'HIGH' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:122: error: 'digitalWrite' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:126: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: At global scope:
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:266: error: 'boolean' does not name a type
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In constructor 'VarSpeedServo::VarSpeedServo()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:283: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'uint8_t VarSpeedServo::attach(int, int, int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'OUTPUT' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:297: error: 'pinMode' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:304: error: 'isTimerActive' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::detach()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:315: error: 'isTimerActive' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::write(int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:326: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::writeMicroseconds(int)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: 'byte' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:334: error: expected `;' before 'channel'
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:335: error: 'channel' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:343: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'void VarSpeedServo::slowmove(int, uint8_t)':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:377: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: 'byte' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:380: error: expected `;' before 'channel'
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:381: error: 'channel' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:388: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::read()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:407: error: 'map' was not declared in this scope
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp: In member function 'int VarSpeedServo::readMicroseconds()':
C:\Users\Henrik\Documents\Arduino\libraries\VarSpeedServo\VarSpeedServo.cpp:414: error: 'clockCyclesPerMicrosecond' was not declared in this scope


Code:
#include <VarSpeedServo.h>
int BlueLed = 13;
VarSpeedServo servo1;  //Create a servo object

void setup() {
     // put your setup code here, to run once:
  servo1.attach(4, 0, 180); //Lisab servo PIN 1 servo objektile
   //configure pin2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
   int speed = 10;
   int angle = 45;
   int angle2 = 0;
   int speed2 = 30;
   int sensorVal = digitalRead(2);
   //valjastab miskile registrile sensorVal sisu
   Serial.println(sensorVal);
   switch (sensorVal) {
     case LOW:
       servo1.slowmove(angle2, speed2);
       break;
     case HIGH:
       servo1.slowmove (angle, speed);
       break;
     }


   
Logged

my own world
Offline Offline
Newbie
*
Karma: 0
Posts: 26
We are all geeks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What ide are you using??
Download the latest and try again...
I am using 1.0.5 and it compiles on mine just fine.
Did you install the library correctly?
Did you point your IDE to look in the the correct directory?

Sorry I do not have an extra arduino to run the code right now
but like I said  it compiles....
Logged

Signatures are stupid!

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Tnx Timcki! Got it running. The library, when taken from downloaded unpacked folder was copied to inside multiple same-named folders. I removed the intermittent useless folders and now it compiles nicley!

 smiley

Logged

my own world
Offline Offline
Newbie
*
Karma: 0
Posts: 26
We are all geeks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad to hear it!!
Logged

Signatures are stupid!

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone
I'm totally new to robotics and would like to know how to use VarSpeedServo when using Wire library, as my servos will be connected to servo control board.
Below is a simple sketch, can someone add to this sketch the varspeedservo example so I can use it as a template please?

Thanks for any help

#include <Wire.h>

#define ADDRESS 0x61                   // The address of the SD21
#define SERVO 0x43        
void setup(){
  Wire.begin();
}

void loop(){
  Wire.beginTransmission(ADDRESS);
    Wire.write(SERVO);
    Wire.write(255);
    Wire.endTransmission();
  delay(1000);
  
}
« Last Edit: September 13, 2013, 05:45:54 am by sanok » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, i'm new to the Arduino world and need some help understanding this library. i've the done the LED and Servo examples that come standard with the software. My project involves controlling 2 servos with a PS2 controller. i got it working using a modified version of Bill Porter's example sketch that came with his library. but now i'd like to control the speed of the servos. i'm very new to this and wondered if anyone can help me and explain how to use the VarSpeedServo library in layman's terms.

Here's what i have so far, but i get a lot of errors:
Code:
#include <VarSpeedServo.h>

#include <PS2X_lib.h>  //for v1.6


PS2X ps2x; // create PS2 Controller Class

//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
int LX;
int LY;
VarSpeedServo myservo;  // create servo object to control a servo
VarSpeedServo myservo2;

void setup(){
 Serial.begin(57600);

 //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
 
 error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
 
 {
  myservo.attach(5,0,180);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(6,0,180);
   
}
 
 if(error == 0){
   Serial.println("Found Controller, configured successful");
   Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
  Serial.println("holding L1 or R1 will print out the analog stick values.");
  Serial.println("Go to www.billporter.info for updates and to report bugs.");
 }
   
  else if(error == 1)
   Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
   
  else if(error == 2)
   Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
   
  else if(error == 3)
   Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
   
   //Serial.print(ps2x.Analog(1), HEX);
   
   type = ps2x.readType();
     switch(type) {
       case 0:
        Serial.println("Unknown Controller type");
       break;
       case 1:
        Serial.println("DualShock Controller Found");
       break;
       case 2:
         Serial.println("GuitarHero Controller Found");
       break;
     }
 
}

void loop(){
   /* You must Read Gamepad to get new values
   Read GamePad and set vibration values
   ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
   if you don't enable the rumble, use ps2x.read_gamepad(); with no values
   
   you should call this at least once a second
   */
   
   
   
 if(error == 1) //skip loop if no controller found
  return;
 
 if(type == 2){ //Guitar Hero Controller
   
   ps2x.read_gamepad();          //read controller
   
   if(ps2x.ButtonPressed(GREEN_FRET))
     Serial.println("Green Fret Pressed");
   if(ps2x.ButtonPressed(RED_FRET))
     Serial.println("Red Fret Pressed");
   if(ps2x.ButtonPressed(YELLOW_FRET))
     Serial.println("Yellow Fret Pressed");
   if(ps2x.ButtonPressed(BLUE_FRET))
     Serial.println("Blue Fret Pressed");
   if(ps2x.ButtonPressed(ORANGE_FRET))
     Serial.println("Orange Fret Pressed");
     

    if(ps2x.ButtonPressed(STAR_POWER))
     Serial.println("Star Power Command");
   
    if(ps2x.Button(UP_STRUM))          //will be TRUE as long as button is pressed
     Serial.println("Up Strum");
    if(ps2x.Button(DOWN_STRUM))
     Serial.println("DOWN Strum");
 
 
    if(ps2x.Button(PSB_START))                   //will be TRUE as long as button is pressed
         Serial.println("Start is being held");
    if(ps2x.Button(PSB_SELECT))
         Serial.println("Select is being held");

   
    if(ps2x.Button(ORANGE_FRET)) // print stick value IF TRUE
    {
        Serial.print("Wammy Bar Position:");
        Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
    }
 }

 else { //DualShock Controller
 
    ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed
   
     if(ps2x.Button(PSS_LY))
   
     LY = ps2x.Button(PSS_LY);
     {
     LY = map(ps2x.Analog(PSS_LY),  0, 255, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
     myservo.slowmove(LY,0);
     delay(15);                           // waits for the servo to get there
     }
     
     if(ps2x.Button(PSS_LX))
     LX = ps2x.Button(PSS_LX);          // reads the value of the potentiometer (value between 0 and 1023)
     {
     LX = map(ps2x.Analog(PSS_LX),  0, 255, 0, 180);    // scale it to use it with the servo (value between 0 and 180)
     myservo2.slowmove(LX,0);
     delay(15);
     }   
         
     
   
 }
 
 
 delay(50);
     
}
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i get a lot of errors
Sadly, no members of the Arduino forum that I know are trained in Telepathy so unless you post what the errors are we really can't be of much help  smiley-grin

Your code complied fine on my computer (I have the library's installed). My guess, would be that you installed one of your library's  wrong or you need to update them to make them compatible with the new version of Arduino IDE (assuming your running it).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my bad. here's the errors i get. ill try to reinstall the library.

 
Code:
ps2x_varspeed_test:16: error: 'Servo' does not name a type
ps2x_varspeed_test:17: error: 'Servo' does not name a type
ps2x_varspeed_test.ino: In function 'void setup()':
ps2x_varspeed_test:27: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:28: error: 'myservo2' was not declared in this scope
ps2x_varspeed_test.ino: In function 'void loop()':
ps2x_varspeed_test:126: error: 'myservo' was not declared in this scope
ps2x_varspeed_test:134: error: 'myservo2' was not declared in this scope
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: