Society of Robots - Robot Forum

Software => Software => Topic started by: UnicornKing on October 16, 2009, 11:56:24 PM

Title: Axon MCU with servoes
Post by: UnicornKing on October 16, 2009, 11:56:24 PM
i'm starting to build robots fresh meaning this is my first time. I was trying to get a servo to center with

wheel_left(700);
delay_ms(20);

i deleted everything in control.c from the method (or function depending on your programing language) photovore() and placed that 2 line of code. whenever run the program the servo only moves a fraction of a degree b4 stopping. if i keep running the program the servo will keep moving until it hits center then it stops. it does this from both sides reaching the same center. i dont know what i'm doing wrong can someone inform me help me with some troubleshoots?
Title: Re: Axon MCU with servoes
Post by: Webbot on October 17, 2009, 12:22:43 PM
When you send the servo a command eg via 'wheel_left' then it knows where it needs to move to and where it currently is and so starts to move. But you need to do repeatedly - ie keep telling the servo where to move to.
You say 'if i keep running the program' - which sounds bad. Embedded programs shouldn't finish - there should be an infinite loop somewhere.
So as a simple case have you tried wrarpping your code in a while(1) ie do the following forever such as:-
Code: [Select]
while(1){
wheel_left(700);
delay_ms(20);
}
Title: Re: Axon MCU with servoes
Post by: UnicornKing on October 17, 2009, 01:31:24 PM
ah thank-you for the clarity and yes i have tried but your logic sounds very reasonable so it maybe that my infinite loop was incorrect so i will try to get it to work using the loop.
Title: Re: Axon MCU with servoes
Post by: UnicornKing on October 17, 2009, 04:14:17 PM
oh i fixed my problem i deleted too much of the original program so when i added all the propramed goodies my small script worked

but now i have another question. how would i go about programming logic to make the servo go back to center every time i physically move the servo myself without rerunning the code.
Title: Re: Axon MCU with servoes
Post by: Admin on October 18, 2009, 08:31:24 AM
Quote
how would i go about programming logic to make the servo go back to center every time i physically move the servo myself without rerunning the code.
You would need to add a sensor to the wheel so that the Axon knows the servo isn't centered.