Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
/****************************************************************************** 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 variablesint sharp_IR_reading=0;int scan_thresh=30;//threshold value of scanning sensorint scan_angle=1000;//position of scanner, in units of servo commandint 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 runvoid 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; } } }
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);
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 }
/****************************************************************************** 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 variablesint sharp_IR=0;int scan_thresh=30;//threshold value of scanning sensorint scan_angle=1000;//position of scanner, in units of servo commandint 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 runvoid 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(); } } }
#define servo_scan( position ) servo(PORTE,5,position)#define wheel_left( position ) servo(PORTE,6,position)#define wheel_right( position ) servo(PORTE,7,position)
Woohoo after 26 posts and 3 hours of debugging I'm Done!!! Here's the final code.
video, please QuoteWoohoo 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