Author Topic: $50 Robot success! Programming question...  (Read 1807 times)

0 Members and 1 Guest are viewing this topic.

Offline RICEKING212Topic starter

  • Jr. Member
  • **
  • Posts: 11
  • Helpful? 0
$50 Robot success! Programming question...
« on: August 07, 2009, 01:53:58 PM »
Just yesterday I finished my $50 robot although it costed me about $190 because I ordered some extra fixings. Right now I'm using the object follow code for my robot and it's working great! I can't express how happy I am! Now since I have built the robot and played with it a lot, I want to make it an object avoider robot. I found the code but I don't really know how to put it in. The code that the Admin made for object following was simple to put in because it came with instructions and they were in files, but the code I found is just text, so I'm not quite sure how to put it in. Heres the code:

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.
* $50 Robot with Sharp IR using Stampy Technology v1, May 19th, 2007
* Simple case-based method for a robot to do edge detection.

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

//global variables
int sharp_IR_reading=0;

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)
//lower (-) goes right
//higher (+) goes left
//30 far right, 50 straight, 56 far left (until it jams)


if (sharp_IR_reading > scan_thresh)//object detected
if (scan_angle>41) //overflow protection
scan_angle-=2;//scan right
else //object not detected
if (scan_angle<=max_scan_angle) //maximum servo angle
scan_angle+=2; //scan left
else //if scanned all the way, this forces it to start over

//servo scan code

//automatically calculates threshold value before run
void autocalibrate(void)
scan_thresh=a2dConvert8bit(3);//sensor reading

int main(void)


delay_cycles(42000);//two second wait delay

/*********ADD YOUR CODE BELOW THIS LINE **********/

//find thresholds



if (sharp_IR_reading > scan_thresh)


//object is centered

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

return 0;

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

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.

robot_turn_left(); and robot_turn_right(); and robot_go_straight();
Dont want to deal with speed?
Just call this function and it will 'just work.'

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.

Reads analog pin. For example, set 'pin' to 5 to read PC5.
'variable' will store the value.


Soon I will be making a video of my robot, but for now, i want to experiment with different code. If you could tell me how to put text code into my robot, I would be in your debt.
Thank you for your time and knowledge

Offline Finnik

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 4
Re: $50 Robot success! Programming question...
« Reply #1 on: August 14, 2009, 04:37:18 AM »
You should take a look at step 4 of the 50$ robot tutorial, there it's explained in detail how to compile your C code into a .hex file and how to upload it to your robot.

Think outside the box... inside is to crowded.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: $50 Robot success! Programming question...
« Reply #2 on: August 23, 2009, 09:58:57 AM »
I want to make it an object avoider robot.



and you're done! :P


Get Your Ad Here