|
|
|
|
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 20, 2009, 09:53:46 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Sept 30th - The
5th SoR Robot contest
is now open! Win an Axon II!
Robot Forum
72,667
Posts in
9,267
Topics by
5,292
Members
Latest Member:
lepomis
Robot Forum
>
Software
>
Software
>
Stampy Code For Axon problems
0 Members and 1 Guest are viewing this topic.
Pages:
[
1
]
Author
Topic: Stampy Code For Axon problems (Read 1916 times)
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Stampy Code For Axon problems
«
on:
January 16, 2009, 07:35:35 PM »
I'm trying to use the edge detection algorithm for the stampy sumo robot on the axon. This is my current code, but For some reason the wheels are not spinning, and my servo just turns all of the way to the right, and doesn't change when I put my hand in front of it. I'm also trying to add a printf function to see exactly what is going on, but it doesn't seem to want to compile with it in there. Can someone help me and see what's wrong with the code?
current code:
Code:
/****************************************************************************
*
* Copyright (c) 2008 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.
*
****************************************************************************/
//Add your code here
//global variables
int sharp_IR_reading=0;
int scan_thresh=30;//threshold value of scanning sensor
int scan_angle=1000;//position of scanner, in units of servo command
int max_scan_angle=833;//maximum position scanner can rotate to (57)
long int wheel_left=600;
long int wheel_right=600;
//this function causes scanning servo to center on edge of object
//automatically calculates threshold value before run
void autocalibrate(void)
{
scan_thresh=a2dConvert8bit(3);//sensor reading
}
void scan(void)
{
//lower (-) goes right
//higher (+) goes left
//30 far right, 50 straight, 56 far left (until it jams)
/*psuedocode
object is detected
scan right object detected
object not detected
scan left until object detected*/
sharp_IR_reading=a2dConvert8bit(3);
if (sharp_IR_reading > scan_thresh)//object detected
{
if (scan_angle>529) //overflow protection
scan_angle-=20;//scan right
}
else //object not detected
{
if (scan_angle<=max_scan_angle) //maximum servo angle
scan_angle+=20; //scan left
//else //if scanned all the way, this forces it to start over
//
scan_angle=30;
}
//servo scan code
servo_scan(scan_angle);
}
void control(void)
{
while(1)
{
scan();
//object on left
if(scan_angle < 570)
{//go left
wheel_left=800;
wheel_right=800;
}
//object on right
else if(scan_angle > 830)
{//go right
wheel_left=550;
wheel_right=550;
}
//object is centered
else
{//go straight
wheel_left=800;
wheel_right=550;
}
}
}
printf code:
Code:
rprintf("Sharp_IR=%d, IR_Servo=%d%d, L_wheel=%d%d, R_wheel=%d%d\r\n",Sharp_Ir_Reading, servo_scan, wheel_left, wheel_right);
Logged
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: Stampy Code For Axon problems
«
Reply #1 on:
January 16, 2009, 07:50:46 PM »
Thats because you don't have any code to tell your servos to do anything
For example:
wheel_left=800;
wheel_right=550;
declares servo angles, but you don't actually send commands to the servos!
Logged
subscribe to SoR's YouTube account
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #2 on:
January 16, 2009, 10:03:10 PM »
Yes I do, it's right under
void control(void)
Logged
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: Stampy Code For Axon problems
«
Reply #3 on:
January 16, 2009, 11:34:21 PM »
Ummmm no you don't . . .
It should be something like this:
Code:
while(1)
{
scan();
//object on left
if(scan_angle > 570)
robot_turn_left();
//object on right
else if(scan_angle < 410)
robot_turn_right();
//object is centered
else
robot_go_straight();
delay_cycles(400);//a small delay to prevent crazy oscillations
}
Where a function such as robot_turn_left(); commands servos.
Logged
subscribe to SoR's YouTube account
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #4 on:
January 17, 2009, 10:26:00 AM »
Ok I see what your talking about, and I added those in but the wheels still won't turn. This is my code:
Code:
/****************************************************************************
*
* Copyright (c) 2008 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.
*
****************************************************************************/
//Add your code here
//global variables
int sharp_IR=0;
int scan_thresh=30;//threshold value of scanning sensor
int scan_angle=1000;//position of scanner, in units of servo command
int max_scan_angle=527;//maximum position scanner can rotate to (57)
long int wheel_left=600;
long int wheel_right=600;
//this function causes scanning servo to center on edge of object
//automatically calculates threshold value before run
void robot_right(void)
{//go right
wheel_left=550;
wheel_right=550;
}
void robot_left(void)
{
wheel_left=800;
wheel_right=800;
}
void robot_straight(void)
{
wheel_left=800;
wheel_right=550;
}
void autocalibrate(void)
{
scan_thresh=a2dConvert8bit(3);//sensor reading
}
void scan(void)
{
//lower (-) goes left
//higher (+) goes right
//1000 far right, 700 straight, 527 far left (until it jams)
/*psuedocode
object is detected
scan right object detected
object not detected
scan left until object detected*/
sharp_IR=a2dConvert8bit(3);
if (sharp_IR > scan_thresh)//object detected
{
if (scan_angle>529) //overflow protection
scan_angle-=20;//scan left
}
else //object not detected
{
if (scan_angle<=max_scan_angle) //maximum servo angle
scan_angle+=20; //scan right
else
scan_angle=1000;
}
//servo scan code
servo_scan(scan_angle);
}
void control(void)
{
while(1)
{
autocalibrate();
scan();
//object on left
if(scan_angle < 570)
{
robot_left();
}
//object on right
else if(scan_angle > 830)
{
robot_right();
}
//object is centered
else
{
robot_straight();
}
}
}
Logged
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #5 on:
January 17, 2009, 10:56:40 AM »
I got my printf function working and I'm confused at what I was getting in hyperterminal. What's with the right wheel and the ir servo?
Sharp_IR=84, IR_Servo=750550, L_Wheel=0550, R_Wheel=08695
Also, It says that that left wheel is getting 550, but the wheel still isn't turning, I tested the servos they're fine, and I made sure they were in the right ports and they are.
«
Last Edit: January 17, 2009, 11:01:52 AM by Jdog
»
Logged
Razor Concepts
Supreme Robot
Helpful? 33
Offline
Posts: 1,076
razorconcepts.net
Re: Stampy Code For Axon problems
«
Reply #6 on:
January 17, 2009, 11:56:09 AM »
Right now you are only changing the integer values. That isnt actually commanding the servos to move. You have to create a servo (there should be some in hardware.c or something), and then do servo_left(wheel_left); at the end of control.
Logged
www.razorconcepts.net
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #7 on:
January 17, 2009, 01:10:30 PM »
I think I already had that, do you mean this:
Code:
#define servo_scan( position ) servo(PORTE,5,position)
#define wheel_left( position ) servo(PORTE,6,position)
#define wheel_right( position ) servo(PORTE,7,position)
«
Last Edit: January 17, 2009, 01:12:04 PM by Jdog
»
Logged
Razor Concepts
Supreme Robot
Helpful? 33
Offline
Posts: 1,076
razorconcepts.net
Re: Stampy Code For Axon problems
«
Reply #8 on:
January 17, 2009, 01:52:10 PM »
Alright, so in control, at the end of the while loop, do wheel_left(wheel_left); and so on. Then, after that, do delay_ms(20);
«
Last Edit: January 17, 2009, 01:54:19 PM by Razor Concepts
»
Logged
www.razorconcepts.net
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #9 on:
January 17, 2009, 07:35:09 PM »
Thank You everybody who answered, I just have a little bit more small modifications, but everything is working almost right. I'll post my final code when I'm done.
Logged
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #10 on:
January 17, 2009, 08:10:08 PM »
Woohoo after 26 posts and 3 hours of debugging I'm Done!!! Here's the final code.
Logged
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: Stampy Code For Axon problems
«
Reply #11 on:
January 18, 2009, 02:07:50 AM »
video, please
Quote
Woohoo after 26 posts and 3 hours of debugging I'm Done!!! Here's the final code.
Your first post and last post are 25 hours apart
Logged
subscribe to SoR's YouTube account
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #12 on:
January 18, 2009, 03:23:52 PM »
Quote from: Admin on January 18, 2009, 02:07:50 AM
video, please
Quote
Woohoo after 26 posts and 3 hours of debugging I'm Done!!! Here's the final code.
Your first post and last post are 25 hours apart
Actually it was a little more because I had another post but you said I was getting off topic so I started a new thread.
Anyway here's the video:
http://www.youtube.com/watch?v=33sPmqq4fL4
LQ
|
HQ
Also I added my new edited code. I now have it using the autocalibrate function, I added code so that it goes backwards if it gets too close to something and I commented it so that someone who doesn't know much about programming can understand it and hopefully learn from it.
Logged
Admin
Administrator
Supreme Robot
Helpful? 62
Online
Posts: 8,610
Re: Stampy Code For Axon problems
«
Reply #13 on:
January 19, 2009, 02:58:14 AM »
cool, I just added this to the
Axon examples page
Got a pic you'd like me to use?
Logged
subscribe to SoR's YouTube account
Jdog
Robot Overlord
Helpful? 1
Offline
Posts: 227
Re: Stampy Code For Axon problems
«
Reply #14 on:
January 20, 2009, 06:12:29 PM »
Yea, This one is good.
I will also upload new pics as I upgrade it.
Logged
Pages:
[
1
]
Jump to:
Please select a destination:
-----------------------------
General Misc
-----------------------------
=> Misc
=> Robot Videos
-----------------------------
Software
-----------------------------
=> Software
-----------------------------
Electronics
-----------------------------
=> Electronics
-----------------------------
Mechanics and Construction
-----------------------------
=> Mechanics and Construction
Related Topics
Subject
Started by
Replies
Views
Last post
Problems with LV-MaxSonar-EZ1 code
Software
Brandon121233
8
2456
May 30, 2007, 08:38:29 PM
by
Brandon121233
Stampy robot code
Software
newbie
28
3815
July 25, 2007, 03:31:16 AM
by
Admin
Stampy Edge Detection For Axon
Software
Jdog
16
1210
January 16, 2009, 07:20:29 PM
by
Jdog
Arduino Code for Stampy algorithm
Software
jkflorek
2
585
March 19, 2009, 02:25:30 AM
by
Admin
Advertise on this Forum
Loading...