Author Topic: Servo Half Speed Code  (Read 859 times)

0 Members and 1 Guest are viewing this topic.

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Servo Half Speed Code
« on: February 13, 2013, 09:50:31 PM »
Hello,

I was wondering if someone could look at my code to see if its correct for running servos (HS-625MG) at half speed.  These are hacked for continuous rotation.  The center is 1500 and the range is 600 usec to 2400 usec

http://www.servocity.com/html/hs-625mg_ultra_speed.html

Code: [Select]
else if (tempbyte==leftwheel)
{
act_setSpeed(&servo,1050);

    return 0;
}
else if (tempbyte==rightwheel)
{
act_setSpeed(&servo,1950);

    return 0;
}

Thankss

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 742
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Servo Half Speed Code
« Reply #1 on: February 13, 2013, 11:49:43 PM »
Other than some funky indentation, looks fine to me.

It occurs to me that I'm not sure whether continuous rotation servos' speeds vary linearly with the PWM... but it's probably close enough.
I

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Servo Half Speed Code
« Reply #2 on: February 14, 2013, 12:38:23 PM »
Looks like you are using WebbotLib - in which the second parameter to the 'act_setSpeed' is wrong (read the documentation). Its not the pulse length but rather a number between -127 and +127.

So just use say -64 and 64 instead of 1050 and 1950.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #3 on: February 14, 2013, 01:18:12 PM »
ok thank you for the help!

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #4 on: February 14, 2013, 10:52:37 PM »
Ok I just tested.  I forgot to mention that I want this one servo (my commands are bit misleading, I will change them) to rotate clockwise and counterclockwise.   so when tempbyte = 1, rotate clockwise.  when tempbyte = 2 , rotate counterclockwise

When I tested with the code below, when 'leftwheel' was received, it just set to halfspeed, and then when 'right wheel' was received, it just went full speed.  it might've been the other way around. so how would i set to rotate clockwise and counterclockwise.  I thought thats what this was doing with the code below
Code: [Select]
else if (tempbyte==leftwheel)
{
act_setSpeed(&servo,-64);

    return 0;
}
else if (tempbyte==rightwheel)
{
act_setSpeed(&servo,64);

    return 0;
}

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Servo Half Speed Code
« Reply #5 on: February 15, 2013, 02:31:34 PM »
Would need to see the definition of your variable 'servo'
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #6 on: February 15, 2013, 11:26:36 PM »
Well I'm using PD so its defined in there.   Center is 1500  range 600 - 2400 reverse direction not set

Also my servo is starting HIGH (starts constantly spinning at first).  I used -124 and 124 and that changed direction, but -64 and 64 doesnt.  Doesnt make sense.  The servo should be off too because  I wrote act_setSpeed(&servo,0); when no tempbyte received

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: Servo Half Speed Code
« Reply #7 on: February 16, 2013, 07:38:20 PM »
Suggest you create a new very simple project that takes no inputs - ie its appControl just does an act_setSpeed for a given value.
eg just have the following in appControl
act_setSpeed(&servo, -64);

This way you know that the rest of your program isn't sending other values to the servo.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #8 on: February 17, 2013, 10:10:43 PM »
Ok this is weird.  It's like its not even responding to my code.  No other values are being sent.  I set the speed to zero if its not receiving a byte but it still keeps turning continuously.  When I continuously send it a value 124, it tries to slow down, but just keeps spinning, I dont understand. 

Would it have anything do with that I put a voltage regulator to step down my supply of 12v to a 5v the servo can handle?

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #9 on: February 18, 2013, 07:20:00 PM »
Waittt I think I may have an idea of what it could be.    When I was modifying the servo with this tutorial http://www.societyofrobots.com/actuators_modifyservo.shtml
I didn't set the servo to zero and glue down the pot.  Could this be my problem?  I dont want to take my servo apart for nothing so some verification would be nice.    It seems like that would be the issue.

Thanks!

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #10 on: February 19, 2013, 04:35:57 PM »
Ok I centered the servo so nothing happens when I start the robot. Now when I send cc, it slowly turns in pulses.  The same goes for right wheels

Code: [Select]
else if (tempbyte== cc)
act_setSpeed (&servo, -124);
delay_ms(20);

It's setting the same speed no matter what I send to it.  I sent a 600 and the same thing occurred.

Very odd.  Any idea what's going on?  Do I need to send the send the pulse for longer?
« Last Edit: February 19, 2013, 09:49:02 PM by Sylvestre »

Offline SylvestreTopic starter

  • Robot Overlord
  • ****
  • Posts: 221
  • Helpful? 13
Re: Servo Half Speed Code
« Reply #11 on: February 19, 2013, 09:49:23 PM »
Problem Solved!  My delay was not long enough!

 


Get Your Ad Here

data_list