Author Topic: help: servo control with a pot using webbotlib  (Read 1657 times)

0 Members and 1 Guest are viewing this topic.

Offline dronzerTopic starter

  • Beginner
  • *
  • Posts: 1
  • Helpful? 0
help: servo control with a pot using webbotlib
« on: April 04, 2010, 03:00:03 PM »
hi. I am trying to control a servo with a pot. however, the servo is not following the pot and moving randomly. I am a newbie and iam using webbotlib for the first time. someone please help  :'( ....
this is the code that i have built :

Code: [Select]
#include "sys/atmega168.h"
#include "a2d.h"
#include "servos.h"

#define pot ADC_NUMBER_TO_CHANNEL(5)

//Define servo
SERVO ser=MAKE_SERVO(FALSE,C4,1500,500);

//Createthelist
SERVO_LIST servos[]={&ser};
//Createadriverforthelistofservos
SERVO_DRIVER bank1=MAKE_SERVO_DRIVER(servos);

void appInitHardware(void){
//Initialise the servo controller using software PWM
servosInit(&bank1,TIMER1);
}

//Initialisetheservos
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
act_setSpeed(&ser,1000);
return 0;
}

TICK_COUNT appControl(LOOP_COUNT loopCount,TICK_COUNT loopStart)
{
uint16_t val = a2dConvert10bit(pot);
uint16_t s = interpolate(val, 0, 1023,1000,2000);                                                                
act_setSpeed(&ser,s);  
return 10;                                        
}

this code is just for one servo but ultimately i want to control 6 servos in this manner. that's why i am using webbotlib....someone familiar with webbotlib please help me get this right..... ??? ??? ???
« Last Edit: April 05, 2010, 01:07:50 AM by dronzer »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: help: servo control with a pot using webbotlib
« Reply #1 on: April 06, 2010, 06:07:25 PM »
As per my PM then your problem is here:-
Code: [Select]
uint16_t s = interpolate(val, 0, 1023,1000,2000);

It should be
Code: [Select]
DRIVE_SPEED s = interpolate(val, 0, 1023,DRIVE_SPEED_MIN,DRIVE_SPEED_MAX);

Can you please revert to the forum rather than PMs - thanks
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

 


data_list