rnome
Joined: 18 Dec 2006 Posts: 20 Location: europe (Turkey)
|
multi servo motor driving |
Posted: Sat Aug 04, 2007 6:51 am |
|
|
hi everybody
i m trying to make robot arm with servo motors but i cant find anyway to drive more than 2 servos
Code: |
#include <16F877.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <lcd.c>
int x,pot0,pot1,i;
int16 srv1, srv2;
float kx;
#int_RDA
void RDA_isr()
{
x=getc();
}
void data_bekle() //for my RF hardware (not matter)
{
for(;;){
if(x==85)break;
}
for(;;){
if(x==255)break;
}
for(;;){
if(x!=255)break;
}
}
void servo1(int value){
if(value<=127){
kx=value/127.0;
srv1=500+(int16)(kx*1000);
}
if(value>127){
kx=value/127.0;
srv1=1500+(int16)((kx-1)*1000);
}
for(i=0;i<1;i++){
output_high(pin_d2);
delay_us(srv1);
output_low(pin_d2);
delay_us(3000-srv1);
delay_ms(17);
}
}
void servo2(int value){
if(value<=127){
kx=value/127.0;
srv2=500+(int16)(kx*1000);
}
if(value>127){
kx=value/127.0;
srv2=1500+(int16)((kx-1)*1000);
}
for(i=0;i<1;i++){
output_high(pin_d3);
delay_us(srv2);
output_low(pin_d3);
delay_us(3000-srv2);
delay_ms(17);
}
}
void main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
lcd_init();
for(;;)
{
data_bekle();
pot0=x;
data_bekle();
pot1=x;
servo1(pot0);
servo2(pot1);
lcd_gotoxy(1,1);
printf(lcd_putc, "y=%u x=%u \ns1=%lu s2=%lu ",pot0,pot1,srv1,srv2);
}
}
|
i wrote these codes and it works good but sometimes servos are shaking although values are constant on lcd
On the code servo1() and servo2() functions are generating servo delays for pwm that coming axis datas from a analog joystick.
is there anyone to help me about multiple servo driving algorithm _________________ live fast, never rest and do your best |
|