Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example Design Programming controls for an imaginary robot. The robot has to drive around, use a camera to track a green light, aim using a turret, and.

Similar presentations


Presentation on theme: "Example Design Programming controls for an imaginary robot. The robot has to drive around, use a camera to track a green light, aim using a turret, and."— Presentation transcript:

1 Example Design Programming controls for an imaginary robot. The robot has to drive around, use a camera to track a green light, aim using a turret, and shoot projectiles at the target. The drive system for the robot consists of two independent drive channels, controlled by two separate PWMs driven by two joysticks. The joysticks’ y-axes control the velocities of the drive motors; stopped, forward and reverse. The turret autonomously tracks the target using the CMU Cam2 and is limited in its travel to +/- 45 degrees by a potentiometer. The driver can re-center the turret with a button on the joystick, and can drive the shooter to load and fire with another button. The OI is programmed to have indicators for the drive controls and a “locked-on-target” LED.

2 void main (void) { #ifdef UNCHANGEABLE_DEFINITION_AREA IFI_Initialization (); /* DO NOT CHANGE! */ #endif User_Initialization(); /* You edit this in user_routines.c */ statusflag.NEW_SPI_DATA = 0; /* DO NOT CHANGE! */ while (1) /* This loop will repeat indefinitely. */ { #ifdef _SIMULATOR statusflag.NEW_SPI_DATA = 1; #endif if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */ { /* I'm slow! I only execute every 26.2ms because */ /* that's how fast the Master uP gives me data. */ Process_Data_From_Master_uP(); /* You edit this in user_routines.c */ if (autonomous_mode) /* DO NOT CHANGE! */ { User_Autonomous_Code(); /* You edit this in user_routines_fast.c */ } Process_Data_From_Local_IO(); /* You edit this in user_routines_fast.c */ /* I'm fast! I execute during every loop.*/ } /* while (1) */ } /* END of Main */

3 void Process_Data_From_Master_uP(void) { static unsigned char i; Getdata(&rxdata); /* Get fresh data from the master microprocessor. */ Camera_Process_Data_From_Master_uP(); Default_Routine(); /* Optional. See below. */ /* Add your own code here. (a printf will not be displayed when connected to the breaker panel unless a Y cable is used) */ printf("Port1 Y %3d, X %3d, Fire %d, Top %d\r",pwm01,pwm05,p1_sw_trig,p1_sw_top); /* printf EXAMPLE */ Generate_Pwms(pwm13,pwm14,pwm15,pwm16); Putdata(&txdata); /* DO NOT CHANGE! */ }

4 void Default_Routine(void) { //pwm01 left drive motors //pwm02 right drive motors //pwm03 firing motor //pwm04 shooter loader motor //relay1 turret rotator motor DriveControl(); TurretControl(); ShooterControl(); IndicatorOutput(); } /* END Default_Routine(); */

5 void DriveControl(void) { /*Using pwm01 as left drive motors and pwm02 as right * drive motors. We are limiting the change of the speed of * the drive motors to be less than +/-32. */ int delta = 32;//Allowable change to drive pwms per 26.2ms(tick) pwm01 = DeltaLimiter(delta, pwm01, p1_y); pwm02 = DeltaLimiter(delta, pwm02, p2_y); } int DeltaLimiter(int delta, int pwm, int joy) { if (joy > (pwm + delta)) { return (pwm + delta); } else { if (joy < (pwm - delta)) { return (pwm - delta); } else { return joy; }

6 void TurretControl(void) { int pot = Get_Analog_Value(turret_pot); int lowerBuffer = 10; if (p3_sw_top) { //recalibrate button if (pot < 124) { relay1_fwd = 1; relay1_rev = 0; } else { if (pot > 130) { relay1_fwd = 0; relay1_rev = 1; } else { relay1_fwd = 0; relay1_rev = 0; } } else { if (Get_Tracking_State() & STATE_PAN_ON_TARGET) {// Camera locked int min = 64; int max = 192; if (PAN_SERVO > (127 + lowerBuffer)) { relay1_fwd = DegreeLimiter(min, max, turret_pot); relay1_rev = 0; } else { if (PAN_SERVO < (127 - lowerBuffer)) { relay1_rev = DegreeLimiter(min, max, turret_pot); relay1_fwd = 0; } else { relay1_fwd = 0; relay1_rev = 0; } } else { relay1_fwd = 0; relay1_rev = 0; }

7 int DeltaLimiter(int delta, int pwm, int joy) { if (joy > (pwm + delta)) { return (pwm + delta); } else { if (joy < (pwm - delta)) { return (pwm - delta); } else { return joy; }

8 void ShooterControl(void) { if (p4_sw_trig) { pwm03 = 255; pwm04 = 255; } else { pwm03 = 127; pwm04 = 127; }

9 void IndicatorOutput(void) { //…Code Hidden Switch1_LED = !(int)rc_dig_in01; Switch2_LED = !(int)rc_dig_in02; if (Get_Tracking_State() & STATE_PAN_ON_TARGET ) { Switch3_LED = 1; } else { Switch3_LED = 0; }


Download ppt "Example Design Programming controls for an imaginary robot. The robot has to drive around, use a camera to track a green light, aim using a turret, and."

Similar presentations


Ads by Google