Author Topic: controlling servo position using $50 robot MCU  (Read 1652 times)

0 Members and 1 Guest are viewing this topic.

Offline Alfa_ZuluTopic starter

  • Full Member
  • ***
  • Posts: 92
  • Helpful? 1
controlling servo position using $50 robot MCU
« 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
« Last Edit: July 14, 2010, 10:57:31 PM by Alfa_Zulu »

Offline Choco_liger

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 3
Re: controlling servo position using $50 robot MCU
« Reply #1 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.


Offline Alfa_ZuluTopic starter

  • Full Member
  • ***
  • Posts: 92
  • Helpful? 1
Re: controlling servo position using $50 robot MCU
« Reply #2 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

Offline Conscripted

  • Robot Overlord
  • ****
  • Posts: 291
  • Helpful? 10
Re: controlling servo position using $50 robot MCU
« Reply #3 on: July 15, 2010, 07:03:44 AM »
Can you post your code?

Conscripted

Offline Alfa_ZuluTopic starter

  • Full Member
  • ***
  • Posts: 92
  • Helpful? 1
Re: controlling servo position using $50 robot MCU
« Reply #4 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);

Offline Choco_liger

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 3
Re: controlling servo position using $50 robot MCU
« Reply #5 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

Offline Alfa_ZuluTopic starter

  • Full Member
  • ***
  • Posts: 92
  • Helpful? 1
Re: controlling servo position using $50 robot MCU
« Reply #6 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

Offline Choco_liger

  • Full Member
  • ***
  • Posts: 81
  • Helpful? 3
Re: controlling servo position using $50 robot MCU
« Reply #7 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?

Offline Alfa_ZuluTopic starter

  • Full Member
  • ***
  • Posts: 92
  • Helpful? 1
Re: controlling servo position using $50 robot MCU
« Reply #8 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?

 


data_list