Society of Robots - Robot Forum
Software => Software => Topic started by: dronzer 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 :
#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..... ??? ??? ???
-
As per my PM then your problem is here:-
uint16_t s = interpolate(val, 0, 1023,1000,2000);
It should be
DRIVE_SPEED s = interpolate(val, 0, 1023,DRIVE_SPEED_MIN,DRIVE_SPEED_MAX);
Can you please revert to the forum rather than PMs - thanks