Added bumper switches to the front of the robot, on one each side.
IOIOTruckValues.java Added bumper switch port vales IOIOTruckManager.java Added 2 new digital inputs for them bumper switches. Added if blocks to loop() to check the state of the switches. If either one is pressed, the robot will stop.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
package com.TwentyCodes.android.IOIOTruck;
|
||||
|
||||
import ioio.lib.api.DigitalInput;
|
||||
import ioio.lib.api.DigitalOutput;
|
||||
import ioio.lib.api.IOIO;
|
||||
import ioio.lib.api.PwmOutput;
|
||||
@@ -39,6 +40,8 @@ public class IOIOTruckManager extends IOIOManager {
|
||||
private TB6612FNGMotorDriver mRightMotor;
|
||||
private PwmOutput mShifter;
|
||||
private DigitalOutput mMotorDriverStandBy;
|
||||
private DigitalInput mLeftFrontBumber;
|
||||
private DigitalInput mRightFrontBumber;
|
||||
|
||||
/**
|
||||
* Creates a new IOIOTruckThread
|
||||
@@ -111,6 +114,12 @@ public class IOIOTruckManager extends IOIOManager {
|
||||
|
||||
//enable the motor driver
|
||||
mMotorDriverStandBy = ioio.openDigitalOutput(IOIOTruckValues.MOTOR_DRIVER_STANDBY, true);
|
||||
|
||||
/*
|
||||
* bumper switches in the front
|
||||
*/
|
||||
mLeftFrontBumber = ioio.openDigitalInput(IOIOTruckValues.LEFT_FRONT_BUMPER_PORT);
|
||||
mRightFrontBumber = ioio.openDigitalInput(IOIOTruckValues.RIGHT_FRONT_BUMBER_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +137,7 @@ public class IOIOTruckManager extends IOIOManager {
|
||||
* @see com.TwentyCodes.android.ioio.IOIOThread#onUpdate()
|
||||
*/
|
||||
@Override
|
||||
public void loop() throws ConnectionLostException {
|
||||
public void loop() throws ConnectionLostException, InterruptedException {
|
||||
|
||||
this.setStatLedEnabled(mStatLedValue);
|
||||
|
||||
@@ -136,6 +145,19 @@ public class IOIOTruckManager extends IOIOManager {
|
||||
|
||||
mMotorDriverStandBy.write(mStatLedValue);
|
||||
|
||||
/*
|
||||
* we need to check our sensors before we can make a move.
|
||||
*/
|
||||
if(mLeftFrontBumber.read()){
|
||||
//TODO backup, spin right, drive forward
|
||||
mLeftMotor.setSpeed(0);
|
||||
mRightMotor.setSpeed(0);
|
||||
} else if(mRightFrontBumber.read()){
|
||||
//TODO backup, spin left, drive forward
|
||||
mLeftMotor.setSpeed(0);
|
||||
mRightMotor.setSpeed(0);
|
||||
} else
|
||||
|
||||
/*
|
||||
* if the autonomous routine is running
|
||||
* then drive the truck
|
||||
@@ -148,7 +170,6 @@ public class IOIOTruckManager extends IOIOManager {
|
||||
mLeftMotor.setSpeed(0);
|
||||
mRightMotor.setSpeed(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,4 +87,14 @@ public class IOIOTruckValues extends IOIOValues {
|
||||
*/
|
||||
public static final int STEER_LEFT = 1300;
|
||||
|
||||
/**
|
||||
* IOIO port for the left front bumper switch
|
||||
*/
|
||||
public static final int LEFT_FRONT_BUMPER_PORT = 11;
|
||||
|
||||
/**
|
||||
* IOIO port for the right front bumper switch
|
||||
*/
|
||||
public static final int RIGHT_FRONT_BUMBER_PORT = 12;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user