Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: ed1380 on April 05, 2007, 11:15:45 PM

Title: Photocell sensors + $50 robot blog+rant
Post by: ed1380 on April 05, 2007, 11:15:45 PM
Is there going to be a diference if I put the sensors a certain distance a part. (closer to each other is better, or vise versa)

BTW I'm done with the "motherboard" of the robot. Ugliest soldering I have ever seen. and ruined the pc board a bit :o   150watt gun FTW 8)



Title: Re: Photocell sensors
Post by: zamboniman60 on April 06, 2007, 01:49:28 PM
for future reference, 30w is plenty for almost everything, and 25 is usually better...
Title: Re: Photocell sensors
Post by: Admin on April 06, 2007, 04:18:24 PM
Quote
Is there going to be a diference if I put the sensors a certain distance a part. (closer to each other is better, or vise versa)
i'd recommend making them position adjustable so you can play around with what is best for your robot. the physically closer the sensors are, the less light difference there will be between them. typically 2 or 3 inches is what i'd do.
Title: Re: Photocell sensors
Post by: ed1380 on April 06, 2007, 06:47:15 PM
Quote
the physically closer the sensors are, the less light difference there will be between them.
Isn't tht bad? don't you want there to be more diference so it'll be easier for the robot to see a diference?


I got the servo's today(they were in the mailbox for 7 hours  >:( cause I didn't know they came) I got free upgrade to the 325HB with a baggy of tootsie rolls :o 8) , but they have diferent mounting hardware than admin's did   :-\ . also there was no big red servo horn that was in the pic on the site >:(

maybe I should just change the thread title to $50 robot blog  :D
Title: Re: Photocell sensors + $50 robot blog
Post by: Admin on April 07, 2007, 02:32:53 AM
Quote
Isn't tht bad? don't you want there to be more diference so it'll be easier for the robot to see a diference?
yeap its bad, you want more difference. you could also have them right next to each other, but angled at say 100 degrees from each other. its all personal preference . . .

Quote
I got the servo's today(they were in the mailbox for 7 hours  Angry cause I didn't know they came) I got free upgrade to the 325HB with a baggy of tootsie rolls Shocked Cool , but they have diferent mounting hardware than admin's did   Undecided . also there was no big red servo horn that was in the pic on the site
yea its hard to predict what is included with the servos :-\  and it changes occasionally, too.
ive had to once go out and specially buy the big servo horns cause my design really needed them but the servos didnt come with them.

gotta love the candy servocity gives out :P
i think they do that for big orders, not sure . . . i always do big orders . . .
Title: Re: Photocell sensors + $50 robot blog
Post by: ed1380 on April 07, 2007, 03:58:22 AM
Well the X servo horns are attached to the wheels(5 AOL cd's superglued together 8)). That took an hour or two of careful drilling and trial and error.
Next came the servo mounts. I thought It'd be pretty easy, but was wrong. It took me over 5 hours to make 4 of them ???
So now I'm about to start modding the servos's at 6 in the morning   :o

I think I'm gonna go with them(photocells) being 8" apart (on the corners of the base) and pointed forward and in a bit



Question- According to step 7 here( http://www.societyofrobots.com/actuators_modifyservo.shtml ) you take the slot out of the main gear. On mine the slot is molded into the main gear. So after centering the pot I superglue it and cut the flat pin on the pot?
Cut at red line in pic? the brass thing is plastic on mine.

How would I send a center signal from the mcu to the servo?
plug it in, write code(send 1500ms output port 1) and do that to both and then unplug and continue. I know nothng about programming for now, so can someone write the code.
Title: Re: Photocell sensors + $50 robot blog
Post by: sotu on April 07, 2007, 08:50:14 AM
I live in Norway but can seem to find any stores where they sell servos, only motors. Looks like my only chance is ordering from the internet.
Title: Re: Photocell sensors + $50 robot blog
Post by: hazzer123 on April 07, 2007, 01:26:23 PM
About the servo control, there is a great page here, gives you all the source code for a PIC MCU and is very expandable. http://www.rentron.com/SerialServo.htm.

What i did with the code is change it so that the MCU is compatable with all of the SSC servo controller software. All that is different compared to the servo commander software on the link is that the SSC software sends SYNC byte (255) before the servo number and position.

As for centering the servo, just make the MCU output a wave with high time around 1.5ms, i dont think loads of acuracy matters that much, then alter the potentiometer until it stops turning.

Hope it helps...

Harry
Title: Re: Photocell sensors + $50 robot blog
Post by: ed1380 on April 07, 2007, 01:51:57 PM
Sorry long post
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2007 www.societyofrobots.com
*   (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.
*
* Photovore v1, March 10th, 2007
* Simple case-based method for a robot that chases light.
*
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff


int main(void)
{
//declare variables here
//int i=250;//a 'whatever' variable
int sensor_left=0;//left photoresistor
int sensor_right=0;//right photoresistor
int threshold=8;//the larger this number, the more likely your robot will drive straight


/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
//uartInit();  // initialize the UART (serial port)
//uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
//rprintfInit(uartSendByte);// initialize rprintf system

//timerInit(); // initialize the timer system

configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//rprintf("Initialization Complete\r\n");
/**************************************************/


/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_off();//turn LED on


while(1)
{
//store sensor data
sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4);


//detects more light on left side of robot
if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)
{//go left
servo_left(44);
servo_right(44);
}

//detects more light on right side of robot
else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
{//go right
servo_left(25);
servo_right(25);
}

//light is about equal on both sides
else
{//go straight
servo_left(25);
servo_right(44);
}


/* Servo Test Code
i=250;
while(i>0)
{
servo_left(40);
i--;
}

i=250;
while(i>0)
{
servo_left(24);
i--;
}
*/

//rprintf("Initialization Complete\r\n");

//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);

delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}


/*********************COMMAND LIST*************************

delay_cycles(cycles);
Delays - you can make your robot wait for a certain amount of time with this function.
Put the number of computational cycles to delay in the ().
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
Check servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'


servo_left(speed); and servo_right(speed);
Commands your servos to rotate at a certain speed.
Vary speed (which represents a delay in cycles) from 20 to 50.
Left is for port D0 and right is for port D1.


LED_on(); and LED_off();
Turns on and off your LED. The LED is on port D4.
By bringing port D4 low, you are turning on the LED.


variable=a2dConvert8bit(pin);
Reads analog pin. For example, set 'pin' to 5 to read PC5.
'variable' will store the value.

***********************************************************/
This is admins code for the phtovore.
From what I understand the numbers 25 and 44 mean which servo(right left) But take a look at "note" on bottom




Acording to this
Code: [Select]
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
I if wanted it to send out 1500ms then I would delay .500
So 23/.5=46.
So to set the servo's on center I would change the code to this. no need to loop, cause I just need it to set to center once
Code: [Select]
/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
//uartInit();  // initialize the UART (serial port)
//uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
//rprintfInit(uartSendByte);// initialize rprintf system

//timerInit(); // initialize the timer system

configure_ports(); // configure which ports are analog, digital, etc.
a2dInit(); // initialize analog to digital converter (ADC)
a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

//rprintf("Initialization Complete\r\n");
/**************************************************/


/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_off();//turn LED on


/* Servo Test Code
i=250;
while(i>0)
{
servo_left(46);
i--;
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}


/*********************COMMAND LIST*************************

delay_cycles(cycles);
Delays - you can make your robot wait for a certain amount of time with this function.
Put the number of computational cycles to delay in the ().
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
Check servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'


servo_left(speed); and servo_right(speed);
Commands your servos to rotate at a certain speed.
Vary speed (which represents a delay in cycles) from 20 to 50.
Left is for port D0 and right is for port D1.


LED_on(); and LED_off();
Turns on and off your LED. The LED is on port D4.
By bringing port D4 low, you are turning on the LED.


variable=a2dConvert8bit(pin);
Reads analog pin. For example, set 'pin' to 5 to read PC5.
'variable' will store the value.

***********************************************************/
Or I would change the 46 to 35 according to "note"




NOTE-
Code: [Select]
servo_left(speed); and servo_right(speed);
Commands your servos to rotate at a certain speed.
Vary speed (which represents a delay in cycles) from 20 to 50.
Left is for port D0 and right is for port D1.
But according to this 20-50 sets speed.



I would experiment and try diferent variable, but the programming cable hasn't come in yet. according to the website it hasn't been shipped yet >:(

2 days and still no answer 
Title: Re: Photocell sensors + $50 robot blog
Post by: ed1380 on April 09, 2007, 07:36:41 PM

I ordered my programing cable at 1pm eastern time on thursday and sparkfun just sent out the d*mn cable on monday.  >:(
digikey and servocity sent their stuff out the same day and I got it 3 days later, but with sparkfun I have to wait 10 days
WTF gives >:(
Title: Re: Photocell sensors + $50 robot blog+rant
Post by: Admin on April 19, 2007, 12:17:09 PM
ed, here is the documentation in my SoR_Utils.h file:

Code: [Select]
//************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--;
}
//***************************************

to control a servo you need to send a PWM for a certain length of time. to center a servo it is usually ~1.5ms.

so to calculate,
23/.992*(time in milliseconds) = number of cycles
->
23/.992*(1.5) = 35

so, using that number, you then would do something like:
Code: [Select]
servo_left(35);//1.5ms PWM, left servo remains stationary
i developed this method so its easier for beginners to understand, and yet gives the maximum time resolution required by experts (cycle counting), too.
Title: Re: Photocell sensors + $50 robot blog+rant
Post by: ed1380 on April 19, 2007, 01:40:50 PM
WOOT!!! I was partially right