Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: sean22 on March 09, 2009, 02:49:32 PM
-
SO i just got everything working but the wheels always go in the opposite direction of each other is this normal
-
seems either a servo modding error or a programming error. and are your sensors plugged in properly? this could cause false readings.
-
The servos came modded so i dont think its that so could it be that the resistor in the sensors is to strong
-
well yes, id say that the resistor plays a huge part in this. check your photosensor values in both light and dark with a multimeter. and make sure the resistor is a 1.62k??? or whatever the right resistance is.
-
one servo always has to be mounted the opposite way of the other servo.
-
if i flip the servo over it changes directions
-
if you put a mirror in between your servos and looked at one servo in the mirror does the one behind the mirror look just like that servo? or is it backward?
-
Heres a picture i made
http://www.societyofrobots.com/robotforum/index.php?topic=2962.msg37687#msg37687 (http://www.societyofrobots.com/robotforum/index.php?topic=2962.msg37687#msg37687)
-
ya it looks like that
here is a picture
http://picasaweb.google.com/Rambotics2200/Servo#5311304831536340898 (http://picasaweb.google.com/Rambotics2200/Servo#5311304831536340898)
-
oh ok your good with that then.
Just reverse the code for one servo in your robot_go_straight macro
-
If you shine a torch into 1 photoresistor and then the other, do the servo's change direction?
-
how do i change the robot go straight
-
Can you post up the servo code in SoR_Utils.h? I don't have it in front of me and I don't wanna download it at work.
-
this is the Sor_utils.h
/****************************************************************************
*
* Copyright (c) 2007 www.societyofrobots.com (http://)
* (please link back if you use this code!)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* SoR Utilities v1, March 10th, 2007
*
****************************************************************************/
//AVR includes
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support
//AVRlib includes
#include "global.h" // include global settings
//#include "buffer.h" // include buffer function library
//#include "uart.h" // include uart function library
//#include "rprintf.h" // include printf function library
//#include "timer.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library
//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )
//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00; //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF; //configure all D ports for output
DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')
}
//***************************************
//************DELAY FUNCTIONS************
//wait for X amount of cycles (23 cycles is about .992 milliseconds)
//to calculate: 23/.992*(time in milliseconds) = number of cycles
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
//***************************************
-
if i shine a light into the left photo resistor the right servo changes direction, if i shine a light into the right photo resistor it left servo cahnges direction and slows down quite a bit. when the light is equal the wheels go in opposite directions.
-
Seems like you're missing some macros I found a copy of my header file I posted on here a while back
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_ON(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_OFF(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(1600); // 200 * 8
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 3);
delay_cycles(speed);
PORT_OFF(PORTD, 3);//keep off
delay_cycles(1600); // 200 * 8
}
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 4);
delay_cycles(speed);
PORT_OFF(PORTD, 4);//keep off
delay_cycles(1600); // 200 * 8
}
void robot_turn_left(void)
{
servo_left(200); // 25 * 8
servo_right(200); // 25 * 8
}
void robot_turn_right(void)
{
servo_left(352); // 44 * 8
servo_right(352); // 44 * 8
}
void robot_go_straight(void)
{
servo_left(200); // 25 * 8
servo_right(352); // 44 * 8
}
void hold_position(void)//37
{
servo_left(312);//39 * 8
servo_right(280);//35 * 8
}
You can see individually the macro for left and right is the same, but to get them to go straight in the same direction you have to pulse them differently
NOTE: I multiplied all the values by 8, because I was running at 8MHz not 1MHz
I later added a Macro to make the robot go backwards, where to go forward is:
void robot_go_straight(void)
{
servo_left(200); // 25 * 8
servo_right(352); // 44 * 8
}
Going backward would be:
void robot_go_back(void)
{
servo_left(352); // 25 * 8
servo_right(200); // 44 * 8
}
The best way to calibrate your servos is to sent it a hold position macro, and tweak the numbers inside that macro until your robot holds still, then you can offset the rest of the macros by that difference.
EDIT: Sorry when I say macro, I mean function
-
this is working but, the servos don't move anymore but as a bonus the LED turns on
-
Those functions I beleive are for the microcontroller at 8mhz, he might be running at 1mhz (using smaller numbers for servo like around 30 instead of around 200)
-
Yes, like I said those numbers are multiplied by 8 for running at 8MHz if you're running at 1MHz then divide them all by 8. See the comments in the code.
-
well my chip is broken again i pressed "auto" insted of "AVR" and it did something with the fuses so i have to wait another 2 week for sparkfun to deliver
-
You should always order at least 5 of everything when it comes to electronic parts. Let that be a lesson to ya :P
That way you could easily do this:
http://www.societyofrobots.com/member_tutorials/node/239 (http://www.societyofrobots.com/member_tutorials/node/239)
EDIT: yeah don't order electronic components from sparkfun.com they jack up the price like 3 times what they cost at mouser.com. I only order specialty breakout board from sparkfun.com
-
Mouser is cheaper for alot of thing but $4.74 for the atmeaga 8 and only $3.81 at SFE
Total + shipping to Canada at SFE = 6.99
Total + shipping to Canada at Mouser = 24.74
its really the shipping that gets you
-
I also don't like their service at Sparkfun... always seemes rushed and hurried. I called once to ask about my order and they basically said "if it isnt important GTFO of our phone lines." Also you can't even change your order after you place it... most of the time all you have to do is call and the store will fix things up with you.
-
Intersting..
ive had the exact opposite experience they sent me the wrong programmer i called them and then they sent me the new one right away, and i shipped the old one back and they credited my account with the shipping charges but i do see what you mean when you say they rush you
-
I guess its more like if it's Sparkfuns fault, they will hold your hand and fix everything right away. If it's your fault, it IS your fault so they won't do anything about it...
-
i just got my new micro controller today and a Sharp IR sensor even with the new code and sensors my wheels still go in the same direction could this be beacuse im using the newest version of AVR Studio. here is the same kind of code i posted as last time but for the sharp
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);
}
void robot_turn_left(void)
{
servo_left(25);
servo_right(25);
}
void robot_turn_right(void)
{
servo_left(44);
servo_right(44);
}
void robot_go_straight(void)
{
servo_left(25);
servo_right(44);
}
void hold_position(void)//37
{
servo_left(39);//39
servo_right(35);//35
}
//***************************************
now that i look closer at this i think this could be a servo pulse problem here is the description on the servos im using
1.5mS means it stayed still. Go down towards 1.0mS, and it would turn one way, faster as you moved further away from the 1.5mS "neutral" signal. Then by changing the signal up to 2.0mS, you could make the servo spin the other way.