default_routine(); - pwm mapping...

7
Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs the default mappings of inputs to outputs. * CALLED FROM: this file, Process_Data_From_Master_uP routine * ARGUMENTS: none * RETURNS: void ------------------------------------------------------------------------------*/ void Default_Routine(void) { /*---------- Analog Inputs (Joysticks) to PWM Outputs----------------------- *-------------------------------------------------------------------------- * This maps the joystick axes to specific PWM outputs. */ pwm01 = p1_y; pwm02 = p2_y; pwm03 = p3_y; pwm04 = p4_y; pwm05 = p1_x; pwm06 = p2_x; pwm07 = p3_x; pwm08 = p4_x; pwm09 = p1_wheel; pwm10 = p2_wheel; pwm11 = p3_wheel; pwm12 = p4_wheel; ifi_aliases.h contains all of these macro definitions and more… OUTPUTS INPUTS unsigned char Range: 0 to 255

Upload: bruce-pope

Post on 29-Jan-2016

233 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();- PWM Mapping

/********************************************************************

* FUNCTION NAME: Default_Routine

* PURPOSE: Performs the default mappings of inputs to outputs.

* CALLED FROM: this file, Process_Data_From_Master_uP routine

* ARGUMENTS: none

* RETURNS: void

------------------------------------------------------------------------------*/

void Default_Routine(void)

{

/*---------- Analog Inputs (Joysticks) to PWM Outputs-----------------------

*--------------------------------------------------------------------------

* This maps the joystick axes to specific PWM outputs.

*/

pwm01 = p1_y;

pwm02 = p2_y;

pwm03 = p3_y;

pwm04 = p4_y;

pwm05 = p1_x;

pwm06 = p2_x;

pwm07 = p3_x;

pwm08 = p4_x;

pwm09 = p1_wheel;

pwm10 = p2_wheel;

pwm11 = p3_wheel;

pwm12 = p4_wheel;

ifi_aliases.h contains all of these macro definitions and more…

OUTPUTS

INPUTS unsigned char

Range: 0 to 255

Page 2: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();- 1 Joystick Drive

/*---------- 1 Joystick Drive ----------------------------------------------

*--------------------------------------------------------------------------

* This code mixes the Y and X axes on Port 1 to allow one joystick drive.

* Joystick forward = Robot forward

* Joystick backward = Robot backward

* Joystick right = Robot rotates right

* Joystick left = Robot rotates left

* Connect the right drive motors to PWM13 and/or PWM14 on the RC.

* Connect the left drive motors to PWM15 and/or PWM16 on the RC.

*/

pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);

pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);

Page 3: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();

- Buttons to Relays

/*---------- Buttons to Relays----------------------------------------------

*--------------------------------------------------------------------------

* This default code maps the joystick buttons to specific relay outputs.

* Relays 1 and 2 use limit switches to stop the movement in one direction.

* The & used below is the C symbol for AND

*/

relay1_fwd = p1_sw_trig & rc_dig_in01; /* FWD only if switch1 is not closed. */

relay1_rev = p1_sw_top & rc_dig_in02; /* REV only if switch2 is not closed. */

relay2_fwd = p2_sw_trig & rc_dig_in03; /* FWD only if switch3 is not closed. */

relay2_rev = p2_sw_top & rc_dig_in04; /* REV only if switch4 is not closed. */

relay3_fwd = p3_sw_trig;

relay3_rev = p3_sw_top;

relay4_fwd = p4_sw_trig;

relay4_rev = p4_sw_top;

relay5_fwd = p1_sw_aux1;

relay5_rev = p1_sw_aux2;

relay6_fwd = p3_sw_aux1;

relay6_rev = p3_sw_aux2;

relay7_fwd = p4_sw_aux1;

relay7_rev = p4_sw_aux2;

relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */

relay8_rev = 0;

ifi_aliases.h lists these aliases

Page 4: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();- Limit Switches

/*---------- PWM outputs Limited by Limit Switches ---------*/

Limit_Switch_Max(!rc_dig_in05, &pwm03);

Limit_Switch_Min(!rc_dig_in06, &pwm03);

Limit_Switch_Max(!rc_dig_in07, &pwm04);

Limit_Switch_Min(!rc_dig_in08, &pwm04);

Limit_Switch_Max(!rc_dig_in09, &pwm09);

Limit_Switch_Min(!rc_dig_in10, &pwm09);

Limit_Switch_Max(!rc_dig_in11, &pwm10);

Limit_Switch_Min(!rc_dig_in12, &pwm10);

Limit_Switch_Max(!rc_dig_in13, &pwm11);

Limit_Switch_Min(!rc_dig_in14, &pwm11);

Limit_Switch_Max(!rc_dig_in15, &pwm12);

Limit_Switch_Min(!rc_dig_in16, &pwm12);

void Limit_Switch_Max(unsigned char switch_state, unsigned char *input_value)

{

if (switch_state == CLOSED)

{

if(*input_value > 127)

*input_value = 127;

}

}

Page 5: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();- Feedback LEDs I

/*---------- ROBOT FEEDBACK LEDs------------------------------------------------

*------------------------------------------------------------------------------

* This section drives the "ROBOT FEEDBACK" lights on the Operator Interface.

* The lights are green for joystick forward and red for joystick reverse.

* These may be changed for any use that the user desires.

*/

if (user_display_mode == 0) /* User Mode is Off */

{ /* Check position of Port 1 Joystick */

if (p1_y >= 0 && p1_y <= 56)

{ /* Joystick is in full reverse position */

Pwm1_green = 0; /* Turn PWM1 green LED - OFF */

Pwm1_red = 1; /* Turn PWM1 red LED - ON */

}

else if (p1_y >= 125 && p1_y <= 129)

{ /* Joystick is in neutral position */

Pwm1_green = 1; /* Turn PWM1 green LED - ON */

Pwm1_red = 1; /* Turn PWM1 red LED - ON */

}

else if (p1_y >= 216 && p1_y <= 255)

{ /* Joystick is in full forward position*/

Pwm1_green = 1; /* Turn PWM1 green LED - ON */

Pwm1_red = 0; /* Turn PWM1 red LED - OFF */

}

else

{ /* In either forward or reverse position */

Pwm1_green = 0; /* Turn PWM1 green LED - OFF */

Pwm1_red = 0; /* Turn PWM1 red LED - OFF */

} /*END Check position of Port 1 Joystick

Page 6: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Default_Routine();- Feedback LEDs II

/* This drives the Relay 1 and Relay 2 "Robot Feedback" lights on the OI. */

Relay1_green = relay1_fwd; /* LED is ON when Relay 1 is FWD */

Relay1_red = relay1_rev; /* LED is ON when Relay 1 is REV */

Relay2_green = relay2_fwd; /* LED is ON when Relay 2 is FWD */

Relay2_red = relay2_rev; /* LED is ON when Relay 2 is REV */

 

Switch1_LED = !(int)rc_dig_in01;

Switch2_LED = !(int)rc_dig_in02;

Switch3_LED = !(int)rc_dig_in03;

} /* (user_display_mode = 0) (User Mode is Off) */

else /* User Mode is On - displays data in OI 4-digit display*/

{

User_Mode_byte = backup_voltage*10; /* so that decimal doesn't get truncated. */

}

} /* END Default_Routine(); */

Page 7: Default_Routine(); - PWM Mapping /******************************************************************** * FUNCTION NAME: Default_Routine * PURPOSE: Performs

Places to modify:

• Add variables

• Initialization

• Modify Default_Routine()

• Add to slow loop

• Add to fast loop

• Add to Autonomous code

in: user_routines.c

in: user_routines_fast.c