Skip to content

Argument based operator control

Sulaiman Ghori edited this page Sep 30, 2017 · 1 revision

Argument-based operator control

In order to simplify changes to the operator control program, I decided to switch to arguments for input, both digital and analog. This allows us to make quick changes without complication. It also allows for everybody on the team to fully understand the code, and be able to modify it if necessary.

Global Variables

int isFineControl = false;
int fineControl = 1;

These are the fine control variables. It allows for us to toggle a lower increment in acceleration, allowing for more precise movement.

Update Drive

void updateDrive (int chassisControlLeft, int chassisControlRight, int liftControl) {
  //chassis control
  motorSet(2, (chassisControlRight * fineControl));
  motorSet(3, (chassisControlLeft * fineControl));
  //lift control
  motorSet(6, (liftControl);
  motorSet(7, (liftControl));

}

This is the first function that is argument based. It sets the motors to the speed of the input, and multiplies it by the fine control variable, which is .5 when toggled on and 1 when off.

Fine Control Toggle

void fineControlToggle (int fineBtn) {
  // fine control toggle
  if (fineBtn == 1 &&
      isFineControl == false) { // toggle it on
    isFineControl = true;
    fineControl = .5;
  }
  if (fineBtn == 1 &&
      isFineControl == true) { // toggle it off
    isFineControl = false;
    fineControl = 1;
  }
}

This toggles fine control on and off. When toggled on, it sets the corresponding variable to .5. The input is set by an argument.

Mobile Goal Control

void mobileGoalControl (int moboLiftBtnUp, int moboLiftBtnDown, int moboTiltBtnUp, int moboTiltBtnDown) {
  // mobo lift control
  if (moboLiftBtnUp == 1) {
    motorSet(4, 127);
  }
  if (moboLiftBtnDown == 1) {
    motorSet(4, -127);
  }
  if (moboLiftBtnUp == 0 &&
      moboLiftBtnDown == 0) {
    motorSet(4, 0);
  }
  //mobo tilt control
  if (moboTiltBtnUp == 1) {
    motorSet(5, 127);
  }
  if (moboTiltBtnDown == 1) {
    motorSet(5, -127);
  }
  if (moboTiltBtnUp == 0 &&
      moboTiltBtnDown == 0) {
    motorSet(5, 0);
  }
}
This takes the digital input from the buttons provided in the arguments, and turns motors on and off accordingly.

## Cone Handler Control
```c
void coneHandlerControl(int clawBtnUp, int clawBtnDown, int chainbarBtnUp, int chainbarBtnDown) {
  motorSet(8, (joystickGetAnalog(2,2)));
  motorSet(8, (joystickGetAnalog(2,2)));
  if (chainbarBtnUp == 1) {
    // move up
    motorSet(8, 127);
  }
  if (chainbarBtnDown == 1) {
    // move down
    motorSet(8, -127);
  }
  if (chainbarBtnUp == 0 &&
      chainbarBtnDown == 0) {
    // dont move
    motorSet(8, 0);
  }*/
  // claw control
  if (clawBtnUp == 1) {
    // move up
    motorSet(9, 127);
  }
  if (clawBtnDown == 1) {
    // move down
    motorSet(9, -127);
  }
  if (clawBtnUp == 0 &&
      clawBtnDown == 0) {
    // dont move
    motorSet(8, 0);
  }
}

This takes input from the arguments and sets the motors accordingly, like the mobile goal control. However, currently the chain bar is set by an analog joystick.

Loop

void operatorControl() {
  //TaskHandle driveTaskHandle = taskRunLoop(updateDrive, 50);
  while (isEnabled()) {
    delay(20);
    //chassisControl chassisControlLeft, chassisControlRight, liftControl
    //fineControlToggle fineBtn
    //mobileGoalControl moboLiftBtn, moboTiltBtn
    //coneHandlerControl clawBtn, chainbarBtn
    updateDrive(joystickGetAnalog(1,3), joystickGetAnalog(1,2), joystickGetAnalog(2,2));
    fineControlToggle(joystickGetDigital(1, 7, JOY_DOWN));
    mobileGoalControl(joystickGetDigital(2, 6, JOY_UP), joystickGetDigital(2, 6, JOY_DOWN), joystickGetDigital(2, 8, JOY_UP),
     joystickGetDigital(2, 8, JOY_DOWN));
    coneHandlerControl(joystickGetDigital(2, 5, JOY_UP), joystickGetDigital(2, 5, JOY_DOWN), joystickGetDigital(2, 7, JOY_DOWN),
     joystickGetDigital(2, 7, JOY_UP));
  }
  //taskDelete(driveTaskHandle);
}

Clone this wiki locally