SHARE
TWEET

Kevin's MSP 2013 Robot Arm

ffpaladin Jul 3rd, 2013 7 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.sherolchen.msp;
  2.  
  3. import lejos.nxt.NXTRegulatedMotor;
  4.  
  5. /**
  6.  * A simple interface to a KTong's ARM!!! MWAHAHAHA
  7.  * But we can make it better...we have the technology
  8.  */
  9.  
  10. public class NXTArmAndGripper {
  11.  
  12.         // Member variables used to keep track of various motors
  13.         private NXTRegulatedMotor turningMotor;
  14.         private boolean turnerReversed = false;
  15.         private NXTRegulatedMotor liftingMotor;
  16.         private boolean lifterReversed = false;
  17.         private NXTRegulatedMotor grippingMotor;
  18.        
  19.         // Constructor which assumes an orientation to the various motors
  20.         public NXTArmAndGripper(NXTRegulatedMotor turner,
  21.                                                         NXTRegulatedMotor lifter,
  22.                                                         NXTRegulatedMotor gripper) {
  23.                 turningMotor = turner;
  24.                 liftingMotor = turner;
  25.                 grippingMotor = gripper;
  26.                 // Assumes gripper starts off in closed position.
  27.                 grippingMotor.resetTachoCount();
  28.         }
  29.        
  30.         // Constructor which does not assume an orientation to the various motors
  31.         public NXTArmAndGripper(NXTRegulatedMotor turner, boolean turnReverse,
  32.                                                         NXTRegulatedMotor lifter, boolean liftReverse,
  33.                                                         NXTRegulatedMotor gripper, boolean gripReverse) {
  34.                 turningMotor = turner;
  35.                 turnerReversed = turnReverse;
  36.                 liftingMotor = lifter;
  37.                 lifterReversed = liftReverse;
  38.                 grippingMotor = gripper;
  39.                 // Assumes gripper starts off in closed position
  40.                 grippingMotor.resetTachoCount();
  41.         }      
  42.        
  43.         // Various methods used to control motors (function is obvious form name)
  44.         // The methods are merely wrappers around functions provided by the motor
  45.         // control functions in leJOS
  46.  
  47.         public void turnLeft() {
  48.                 if (turnerReversed) {
  49.                         turningMotor.backward();
  50.                 } else {
  51.                         turningMotor.forward();
  52.                 }
  53.         }
  54.        
  55.         public void turnRight() {
  56.                 if (turnerReversed) {
  57.                         turningMotor.forward();
  58.                 } else {
  59.                         turningMotor.backward();
  60.                 }
  61.         }
  62.        
  63.         public void stopTurning() {
  64.                 turningMotor.stop();
  65.         }
  66.        
  67.         public void liftUp() {
  68.                 if (lifterReversed) {
  69.                         liftingMotor.forward();
  70.                 } else {
  71.                         liftingMotor.backward();
  72.                 }
  73.         }
  74.  
  75.         public void liftDown() {
  76.                 if (lifterReversed) {
  77.                         liftingMotor.forward();
  78.                 } else {
  79.                         liftingMotor.backward();
  80.                 }
  81.         }
  82.        
  83.         public void stopLifting() {
  84.                 liftingMotor.stop();
  85.         }
  86.        
  87.         public void openGripper() {
  88.                 // TODO: Still need to calibrate
  89.                 grippingMotor.rotateTo(0, true);
  90.         }
  91.        
  92.         public void closeGripper() {
  93.                 // TODO: Still need to calibrate
  94.                 grippingMotor.rotateTo(4, true);
  95.         }
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top