Society of Robots - Robot Forum

Software => Software => Topic started by: Alfa_Zulu on July 14, 2010, 09:29:04 PM

Title: controlling servo position using $50 robot MCU
Post by: Alfa_Zulu on July 14, 2010, 09:29:04 PM
Hey,

I'm trying to control a single servo to make it turn to 0 Degrees then pan left and right. so far no matter what code i come up with it just quickly turns anti-clockwise until it hits the mechanical stop and keeps trying to turn. I've even used the code from admin's stampy edge detection tutorial for the robot but it still turns all the way to the right.

the robot does work fine performing its original task of avoiding shadows but i think that the Atmega8 could be damaged because i left it laying around in junk because i thought it had died then later i got it working with the help of joker94.

regards,

Alfa
Title: Re: controlling servo position using $50 robot MCU
Post by: Choco_liger on July 14, 2010, 11:26:42 PM
When you turn it to 0 degrees, it can only turn right.

The center or middle would probably be around 45 depending.

Try between 50 to 30.

Title: Re: controlling servo position using $50 robot MCU
Post by: Alfa_Zulu on July 15, 2010, 04:15:12 AM
by 0 degrees i mean the center so it can go left -90 degrees and right 90 degrees.

i've tried sending it values from 0-100 and it just keeps turning anti-clockwise
Title: Re: controlling servo position using $50 robot MCU
Post by: Conscripted on July 15, 2010, 07:03:44 AM
Can you post your code?

Conscripted
Title: Re: controlling servo position using $50 robot MCU
Post by: Alfa_Zulu on July 15, 2010, 05:27:39 PM
here's what i've come up with, i'm also using the header file from the $50 robot unchanged

Code: [Select]
//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff

int scan_thresh=0;//threshold value of scanning sensor

int scan_angle=30;//position of scanner, in units of servo command
int max_scan_angle=56;//maximum position scanner can rotate to (57)

//this function causes scanning servo to center on edge of object
void scan(void)
{
if (scan_angle<41) //overflow protection
{
scan_angle+=2; //scan right
}

if (scan_angle>=max_scan_angle) //maximum servo angle
{
scan_angle=2; //scan left
}

//servo scan code
servo_left(scan_angle);
Title: Re: controlling servo position using $50 robot MCU
Post by: Choco_liger on July 15, 2010, 08:03:43 PM
Code: [Select]
servo_left(scan_angle);
Firstly(not so much of the problem) you might want to change this to servo_scan unless your using PD0 on your IC for your sharp IR servo. Either way you might want to change it for clarity and switch your servo to PD2.

Also have you checked around 30 to 50 by going,
Code: [Select]
servo_scan(45);
And
Code: [Select]
scan_angle=2
Probably should be
Code: [Select]
scan_angle-=2
Title: Re: controlling servo position using $50 robot MCU
Post by: Alfa_Zulu on July 16, 2010, 02:52:14 AM
Probably should be
Code: [Select]
scan_angle-=2

yeah that was an error from copying it lol, can you see any other reason why it wouldn't work?
dont worry about clarity issues or anything yet, i just would like to get it working to begin with
Title: Re: controlling servo position using $50 robot MCU
Post by: Choco_liger on July 16, 2010, 03:42:24 AM
yeah that was an error from copying it lol, can you see any other reason why it wouldn't work?

Damaged servo?
Title: Re: controlling servo position using $50 robot MCU
Post by: Alfa_Zulu on July 16, 2010, 03:57:11 AM
nope, the servo works perfect with a normal fm receiver, do you know if it's possible that the mcu could be damaged and giving the wrong pulse width?