Class motors

motors

public class motors

This class does all the handling of the robot motors and sensors.

The functions rotate(), track(), GrabObject(), and ReleaseObject() are the functions which get called by the main Seeker class. All other functions are internal to the motors class to enable it to accomplish it's goals.

The state machine diagrams for how this class operates are Tracking, Left Bumper Hit, Rght Bumper Hit, and Rotation.


Field Summary
(package private) static TouchSensor Armb
          Lego touch sensor for arm (when raised to max height)
(package private)  boolean backupdone
          While fixing bumpers, tracks whether the backup state is done
(package private)  boolean bArmIsDown
          Arm state flag
(package private)  boolean bArmIsUp
          Arm state flag
(package private)  boolean bHandIsClosed
          Arm state flag
(package private)  boolean bHandIsOpen
          Arm state flag
(package private) static com.ajile.components.OneShotTimer ChangeStallTimer
          Change Stall Timer Variable
(package private) static CameraImage cImage
          external camera class
(package private) static com.ajile.components.OneShotTimer ColorTimer
          Color Tracking timer
(package private)  boolean colorTimerDone
          Color Tracking flag
(package private)  int currentstate
          State Variables
(package private) static boolean Debug
          Debug Flag
(package private) static int degrees20
          Rotation count for 20 degrees
(package private) static int degrees90
          Rotation count for 90 degrees
(package private)  boolean deltaevent
          Data event flag
(package private)  int dir
          Direction Variable
(package private)  boolean done
          Tracks whether the 20 degree rotation is complete
(package private) static int findColorTime
          Time interval to wait before declare no colors were found.
(package private)  boolean fixBackup
          Flags for when we need to perform certain actions.
(package private)  boolean fixed
          Tracks whether the bumper fixes are complete
(package private)  boolean fixForward
          Flags for when we need to perform certain actions.
(package private)  boolean fixLeftTurn
          Flags for when we need to perform certain actions.
(package private)  boolean fixRightTurn
          Flags for when we need to perform certain actions.
(package private)  boolean forwarddone
          While fixing bumpers, tracks whether the forward state is done
(package private)  boolean handstall
          Hand stall flag
(package private) static int HandStallTime
          Time interval to wait for no movement before assuming a stall has occured
(package private) static com.ajile.components.OneShotTimer HandStallTimer
          Hand Stall Timer Variable
(package private) static TouchSensor leftb
          Lego touch sensor for left bumper
(package private)  boolean leftbHit
          Set true if the left bumper is pressed Set false otherwise
(package private) static Motor mArm
          Lego control for arm motor
(package private) static Motor mHand
          Lego control for hand motor
(package private) static Motor mLeft
          Lego control for left motor
(package private) static int motorArm
          Lego motor speed for arm movement
(package private) static int motorForwFast
          Lego motor speed for fast forward
(package private) static int motorForwSlow
          Lego motor speed for slow forward
(package private) static int motorHand
          Lego motor speed for hand movement
(package private) static int motorRealSlow
          Lego motor speed for real slow
(package private) static int motorTurnFast
          Lego motor speed for fast turn
(package private) static int motorTurnSlow
          Lego motor speed for slow turn
(package private) static int movement
          Rotation count for forward movement
(package private) static Motor mRight
          Lego control for right motor
(package private)  int nextstate
          State Variables
(package private)  boolean noColor
          Color Tracking flag
(package private) static GpioField PortA
          Port A control (used for turning on buzzer)
(package private)  int prevstate
          State Variables
(package private) static TouchSensor rightb
          Lego touch sensor for right bumper
(package private)  boolean rightbHit
          Set true if the right bumper is pressed Set false otherwise
(package private)  boolean rot20left
          Flags for when we need to perform certain actions.
(package private)  boolean rot20right
          Flags for when we need to perform certain actions.
(package private) static RotationSensor sArm
          Lego rotation sensor for arm
(package private) static RotationSensor sHand
          Lego rotation sensor for hand
(package private) static RotationSensor sLeft
          Lego rotation sensor for left wheel
(package private) static RotationSensor sRight
          Lego rotation sensor for right wheel
(package private)  boolean stall
          Stall flag
(package private)  boolean stallfixed
          Stall fixed flag
(package private) static int stallFixInterval
          Time interval to wait before the stall variable can be changed.
(package private) static com.ajile.components.OneShotTimer StallFixTimer
          Stall Fix Timer Variable
(package private) static int stallInterval
          Time interval to wait before the stall variable can be changed.
(package private)  int stallleftcount
          Left stall counter
(package private)  boolean stallread
          Stall read flag
(package private)  int stallrightcount
          Right stall counter
(package private) static int stallTime
          Time interval to wait for no movement before assuming a stall has occured
(package private) static com.ajile.components.OneShotTimer StallTimer
          Stall Timer Variable
(package private)  boolean stalltimeup
          Stall time over flag
(package private) static int timeInterval
          Time interval between polls of direction
(package private)  boolean timeIntervalDone
          Tracks whether the timeInterval has passed
(package private) static com.ajile.components.OneShotTimer timer
          Timer to use for the time intervals between polls
(package private)  boolean turndone
          While fixing the bumpers, tracks whether the 90 degree turns are complete
 
Constructor Summary
motors(CameraImage camera)
          Sets default values for all class members

Also, sets up the event listeners for the multiple input sensors.
 
Method Summary
 void dataEvent(int Count)
          If motors are suppose to be moving, but the rotation count is not changing, a stall timer will start.
private  void fixLeft()
          Runs a small sequence to fix left bumper hit
save rotation value Turn 90 degrees Right while checking for right bumper hits If right bumper hits, back up until it no longer hits Once 90, travel forward a few inches Turn 90 degrees Left while checking for left bumper hits If left bumper hits, recursively call fixLeft, otherwise retrieve old rotation values and return
private  void fixRight()
          Runs a small sequence to fix right bumper hit.
Save rotation value Turn 90 degree Left while checking for left bumper hits If left bumper hits, back up until it no longer hits Once 90, travel forward a few inches Turn 90 degrees Right while checking for right bumper hits If right bumper hits, recursively call fixRight, otherwise retrieve old rotation values and return
 void GrabObject()
          Runs through the sequence of commands to pick up an object.
static void main(java.lang.String[] args)
          Main Function Will use for debugging and unit testing
 void ReleaseObject()
          Opens the gripper to release the object.
 void reset()
          Initializes all the flags and variables used by the class to make sure everything is in the initial state.
 void rotate(int dir)
          Sets the motors to rotate the robot 20 degrees in the given direction.
 boolean track()
          Set the motors to correctly track an object.
Calls GetTrackDirection() to determine which direction to rotate to as well as whether to move forward or not.
Will handle wall/object collision by turning 90 degrees opposite of collision moving a few inches, and swing back to the original orientation.

The state machine diagrams for how this class operates are Tracking, Left Bumper Hit, and Rght Bumper Hit.
 

Field Detail

mRight

static final Motor mRight
Lego control for right motor

mLeft

static final Motor mLeft
Lego control for left motor

mArm

static final Motor mArm
Lego control for arm motor

mHand

static final Motor mHand
Lego control for hand motor

motorRealSlow

static int motorRealSlow
Lego motor speed for real slow

motorHand

static int motorHand
Lego motor speed for hand movement

motorArm

static int motorArm
Lego motor speed for arm movement

motorTurnSlow

static int motorTurnSlow
Lego motor speed for slow turn

motorTurnFast

static int motorTurnFast
Lego motor speed for fast turn

motorForwSlow

static int motorForwSlow
Lego motor speed for slow forward

motorForwFast

static int motorForwFast
Lego motor speed for fast forward

Debug

static boolean Debug
Debug Flag

timeInterval

static int timeInterval
Time interval between polls of direction

stallTime

static int stallTime
Time interval to wait for no movement before assuming a stall has occured

HandStallTime

static int HandStallTime
Time interval to wait for no movement before assuming a stall has occured

stallInterval

static int stallInterval
Time interval to wait before the stall variable can be changed.

stallFixInterval

static int stallFixInterval
Time interval to wait before the stall variable can be changed.

findColorTime

static int findColorTime
Time interval to wait before declare no colors were found.

degrees90

static int degrees90
Rotation count for 90 degrees

degrees20

static int degrees20
Rotation count for 20 degrees

movement

static int movement
Rotation count for forward movement

sLeft

static final RotationSensor sLeft
Lego rotation sensor for left wheel

sRight

static final RotationSensor sRight
Lego rotation sensor for right wheel

sArm

static final RotationSensor sArm
Lego rotation sensor for arm

sHand

static final RotationSensor sHand
Lego rotation sensor for hand

rightb

static final TouchSensor rightb
Lego touch sensor for right bumper

leftb

static final TouchSensor leftb
Lego touch sensor for left bumper

Armb

static final TouchSensor Armb
Lego touch sensor for arm (when raised to max height)

PortA

static final GpioField PortA
Port A control (used for turning on buzzer)

timer

static com.ajile.components.OneShotTimer timer
Timer to use for the time intervals between polls

dir

int dir
Direction Variable

currentstate

int currentstate
State Variables

nextstate

int nextstate
State Variables

prevstate

int prevstate
State Variables

done

boolean done
Tracks whether the 20 degree rotation is complete

turndone

boolean turndone
While fixing the bumpers, tracks whether the 90 degree turns are complete

backupdone

boolean backupdone
While fixing bumpers, tracks whether the backup state is done

forwarddone

boolean forwarddone
While fixing bumpers, tracks whether the forward state is done

fixed

boolean fixed
Tracks whether the bumper fixes are complete

fixLeftTurn

boolean fixLeftTurn
Flags for when we need to perform certain actions.

fixRightTurn

boolean fixRightTurn
Flags for when we need to perform certain actions.

fixForward

boolean fixForward
Flags for when we need to perform certain actions.

fixBackup

boolean fixBackup
Flags for when we need to perform certain actions.

rot20right

boolean rot20right
Flags for when we need to perform certain actions.

rot20left

boolean rot20left
Flags for when we need to perform certain actions.

rightbHit

boolean rightbHit
Set true if the right bumper is pressed Set false otherwise

leftbHit

boolean leftbHit
Set true if the left bumper is pressed Set false otherwise

timeIntervalDone

boolean timeIntervalDone
Tracks whether the timeInterval has passed

cImage

static CameraImage cImage
external camera class

bArmIsUp

boolean bArmIsUp
Arm state flag

bArmIsDown

boolean bArmIsDown
Arm state flag

bHandIsClosed

boolean bHandIsClosed
Arm state flag

bHandIsOpen

boolean bHandIsOpen
Arm state flag

ColorTimer

static com.ajile.components.OneShotTimer ColorTimer
Color Tracking timer

noColor

boolean noColor
Color Tracking flag

colorTimerDone

boolean colorTimerDone
Color Tracking flag

StallTimer

static com.ajile.components.OneShotTimer StallTimer
Stall Timer Variable

HandStallTimer

static com.ajile.components.OneShotTimer HandStallTimer
Hand Stall Timer Variable

ChangeStallTimer

static com.ajile.components.OneShotTimer ChangeStallTimer
Change Stall Timer Variable

StallFixTimer

static com.ajile.components.OneShotTimer StallFixTimer
Stall Fix Timer Variable

stall

boolean stall
Stall flag

handstall

boolean handstall
Hand stall flag

stalltimeup

boolean stalltimeup
Stall time over flag

stallfixed

boolean stallfixed
Stall fixed flag

stallread

boolean stallread
Stall read flag

deltaevent

boolean deltaevent
Data event flag

stallrightcount

int stallrightcount
Right stall counter

stallleftcount

int stallleftcount
Left stall counter
Constructor Detail

motors

public motors(CameraImage camera)
Sets default values for all class members

Also, sets up the event listeners for the multiple input sensors.
Parameters:
camera - Reference to the camera class which will be used for getting the tracking direction
Method Detail

reset

public void reset()
Initializes all the flags and variables used by the class to make sure everything is in the initial state.

main

public static void main(java.lang.String[] args)
Main Function Will use for debugging and unit testing
Parameters:
args - Input arguments passed from the OS

rotate

public void rotate(int dir)
Sets the motors to rotate the robot 20 degrees in the given direction. Will handle wall/object collision by turning 90 degrees opposite of collision moving a few inches, and swing back to the original orientation.

The state machine diagrams for how this function operates are Rotation, Left Bumper Hit, and Rght Bumper Hit.
Parameters:
dir - Direction of rotation. 0=Right, 1=Left

track

public boolean track()
Set the motors to correctly track an object.
Calls GetTrackDirection() to determine which direction to rotate to as well as whether to move forward or not.
Will handle wall/object collision by turning 90 degrees opposite of collision moving a few inches, and swing back to the original orientation.

The state machine diagrams for how this class operates are Tracking, Left Bumper Hit, and Rght Bumper Hit.
Returns:
True if object found. False if timed out (3 sec) looking for object.

fixLeft

private void fixLeft()
Runs a small sequence to fix left bumper hit

fixRight

private void fixRight()
Runs a small sequence to fix right bumper hit.

dataEvent

public void dataEvent(int Count)
If motors are suppose to be moving, but the rotation count is not changing, a stall timer will start. Movement of the rotation count will stop timer. If timer reaches the end, a stall has occurred.
Parameters:
Count - The angular movement of the left rotation sensor

GrabObject

public void GrabObject()
Runs through the sequence of commands to pick up an object. It does this by the following sequence of actions.
  1. Raises the arm till the arm button (Armb) is pushed
  2. Open the gripper all the way (till it stalls)
  3. Lower the arm (sArm rotation count of 5)
  4. Close the hand (sHand rotation count of 19)
  5. Raise the arm

ReleaseObject

public void ReleaseObject()
Opens the gripper to release the object. Sets the motor to open the hand until it stalls, meaning it's open all the way.