Author Topic: WebbotLib servo question.  (Read 1619 times)

0 Members and 1 Guest are viewing this topic.

Offline ConscriptedTopic starter

  • Robot Overlord
  • ****
  • Posts: 291
  • Helpful? 10
WebbotLib servo question.
« on: November 10, 2009, 02:22:51 AM »
Good evening. I'm working on a robotic bug very similar to what you see from the BEAM community. Basically 2 servos with wire for legs. The only real function for bot is moving the servo's back and forth and the bug moves forward or backwards. I'm not very good at computer programming. I'm trying to use Webbots library (V1.8) and an ATMEGA8.

I've been looking through the documentation for the library and I think I'm understanding it ok. I have a question about servo control. How do you move a servo to a given position? I found DRIVE_SPEED_MAX and DRIVE_SPEED_MIN. they move an unmodified servo to the stops. what if you want a position that isn't all the way to either end?


Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
Re: WebbotLib servo question.
« Reply #1 on: November 10, 2009, 06:46:28 PM »
As you've no doubt discovered you can set the position of an un-modified servo by using the act_setSpeed command. This specifies a location which can be:
DRIVE_SPEED_MIN for say fully anti-clockwise, (this value is -ve) and
DRIVE_SPEED_MAX for fully clockwise (this valie is +ve).
The mid-point, also called DRIVE_SPEED_CENTER, represents the neutral centered position and will always have a value of 0.

These names are just shorthands for numbers. The key being that a value of '0' represents center.
So to move a servo halfway between 'center' and 'fully clockwise' then you set a speed of:
('fully clockwise' - 'center') / 2
but since DRIVE_SPEED_CENTER is always 0 then this can be simplified to

Another way to work is to work in percentages - if you are more comfortable with that. ie -100%=Full anti-clockwise and +100%=fully clockwise.
Your program then generates a number in the range -100 to +100.
You can then use the 'interpolate' function (check the docs) to map the value from -100 to +100 into the range DRIVE_SPEED_MIN to DRIVE_SPEED_MAX as follows:
Code: [Select]
int8_t myPercent;  // Assume this variable has your setting from -100 to +100

// Convert myPercent from -100 to +100 into the DRIVE_SPEED_MIN/MAX range
DRIVE_SPEED speed = interpolate(myPercent, -100, 100, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);

// Now set the servo location/speed
act_setSpeed(servo, speed);

Hope that helps
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 ConscriptedTopic starter

  • Robot Overlord
  • ****
  • Posts: 291
  • Helpful? 10
Re: WebbotLib servo question.
« Reply #2 on: November 13, 2009, 01:56:01 AM »
Yes. That answers my question.
Thank you!


Get Your Ad Here