Edge Detection Code for Picaxe 28x1 Help?

MaltiK

Member
This project is based off of a websites project, Stampy from societyofrobots

My setup is:

Picaxe 28x1 using L293D in the motor driver port of the project board
Servo
Sharp IR Rangefinder
2 Standard DC motors /w wheels

The Servo pans with the IR mounted on top.
It will use edge detection to decide where to drive. If no target is available, it would go into a search mode and spin clockwise. Otherwise, it would attempt to drive towards the left side of opposing objects.

Brief description of code wanted

//scanner code
if sharp IR detects object
scanning IR turns left
else //no object detected
scanning IR turns right

//robot motion code
if scanner is pointing far left
robot turns left
else if scanner is pointing far right
robot turns right
else //scanner pointing forward
robot drives straight

It will go left until it spots an object, if nothing detected, it will turn right until it does, resulting in the scanner converging on the left edge of the object.
If the sensor misses the object and rotates to the right to its maximum position, tell the scanner to reset its angle to the far left.

I ask for the code because edge detection is such a common idea, it must have been used in many projects, and so I ask if anyone has any codes I could use for this?
 

BeanieBots

Moderator
It might not be exactly what you're looking for, but there are quite a few bits of robot autonomy code in the Robots section.
Wait long enough and I'm sure someone will write it all for you.
 

MaltiK

Member
It might not be exactly what you're looking for, but there are quite a few bits of robot autonomy code in the Robots section.
Wait long enough and I'm sure someone will write it all for you.
No need for sarcasm :/

I looked in the robots section, if you are serious, as well as the archives forum, and I could only find 3ish SUmo bots, and none have edge detection
 
Last edited:

Mycroft2152

Senior Member
The lack of response is probably due to your attitude.

Read the manual.

Write your program.

When yo9u have problems and are willing to listen to the the responses, post your program.

Good Luck

Myc
 
Last edited:

moxhamj

New Member
Hmm - if you have a distance sensor (a proper commercial $12.50 one) sitting on a servo, and you move the servo from side to side, you will get a series of numbers. Say there was something directly in front of the robot. You might get a number (in cm) of 100, 100, 10,12,10,90,100 as the servo scans from left to right. So the "edge" can be detected by the sudden change in values. So you could subtract a number from the one before it to get the difference, and then look for a big difference. Just a thought.
 

westaust55

Moderator
Maltik has a SRF05 ultrasonic detector ,but in an earlier thread could not get that operational. Unknown what the status is with that topic.

Then jumped to IR detectors for distance and line following and now looking for edge detection.

wrt:
quote:
Brief description of code wanted
[/quote]

Like others, I am prepared to look through the code you have written, but has some bugs but not intending to sit down and write a program for you.
 

MaltiK

Member
I have the code in C, programming language, is it possible to "translate" this into BASIC (errr what the Picaxe uses?) Its most likely not that easy, but if someone could, heres the code in C:

Code:
#include "cereb104.h"
#include "Utilities.h"


signed long int scan_angle=0; //angle of IR servo
unsigned int target_distance=0; //distance away of target
unsigned int distance_thresh=30; //acceptable target detection


//sense
void scan()
	{
	//swap scan directions
	
	/*psuedocode
	while object is detected
		scan left while object detected
	while object not detected
		scan right until object detected*/
	
	target_distance = analog(A3);//check sensor
	
	if (target_distance > distance_thresh)//object detected
		{
		if (scan_angle>-20) //overflow protection
			scan_angle-=1;//scan left
		}
	else //object not detected
		{
		if (scan_angle<130) //overflow protection
			scan_angle+=1; //scan right
		else //if scanned all the way, this forces it to start over
			scan_angle=-20;
		}
		
	//servo scan code
	output_bit(PIN_D2, 1);//139 center
	long_delay_us(130+scan_angle);
	output_bit(PIN_D2, 0);
		
	//printf("angle: %ld distance: %u\r\n", scan_angle, target_distance);//debug code
	}
	

void main() {

//initializing all Cerebellum routines
cereb_init(0);
pwm_init();

//allow short capacitor charge up time
delay_us(5000);

ScanLeft(); //reset IR scanner to straight

//system ready indicator, and start button
set_led(YELLOW, 1);
while(analog(A3) < 100) {printf("%u\r\n", analog(A3));}; //hand swipe to activate robot
set_led(YELLOW, 0);

servoReverse();

while(1)
	{
	delay_us(2500);//so it doesnt change states too fast //2500 works
	
	scan();//locate target
	
	
	//movement actions
	if (scan_angle > 85)//if target is too far on right
		{
		servoRight();//turn towards target
		set_led(YELLOW, 0);
		set_led(GREEN, 1);
		scan_angle-=1;//scanner turns left while robot turns right
		}
	else if (scan_angle < 50)//if target is too far on left
		{
		servoLeft();//turn towards target
		set_led(YELLOW, 1);
		set_led(GREEN, 0);
		scan_angle+=1;//scanner turns right while robot turns left
		}
	else //centered on target
		{
		servoForward();//drive straight
		set_led(YELLOW, 1);
		set_led(GREEN, 1);
		}
	}
	
while(1);
}

//thoughts, try reducing the 5000 delay, maybe doubling negative scan_angle, and reducing turning speed
 

Dippy

Moderator
Maltik,

with respect please be patient.
Not every Forum member spends 24/7 hovering over the Forum waiting to provide an answer. Even WestAust can only manage 12 hours a day :)

Are you the same Malitk who posted a picture of a PCB asking some for some poor soul to spen hours on your behalf translating it to gerber?
http://www.societyofrobots.com/robotforum/index.php?topic=5536.0

You see Maltik, we get posts here by a huge number of people. Some just want help, pointers or snippets... just to get them started in the right direction. The people who the most help are patient and open about the project.

You appear (because thats how it appears, but correct me if I'm wrong) to want people to provide code (possibly taking hours of work) just to save you having to do any work.

WE don't know whether this will give you A* scores in your school project.
You sound like you're about 16 and this sounds like a school project.
If so, no-one will do it for you. Or rather no-one should do it ALL for you.
Help, suggestions and pointers by all means.

But, just between you and me because no-one else is watching, if you can string this out long enough and can get suggestions for every part of your code then you wil have effectively got ALL the code written for you. Ideal. You're happy, we're happy. Its a brilliant idea and no-one will notice.
All you have to do is a multi-thread 'how do I do' question on each part of you code, just be nice and polite, apply flattery and wait...and bingo!


There are one or two people here that will do it ALL for you, they don't require cash... just a little tin of ego-polish.
 

Mycroft2152

Senior Member
It is interesting to note that Maltik found another captive audience and has gotten the same response -- Learn and do it yourself.

I guess we weren't all the special! :)
 
Top