Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. package com.qualcomm.modernrobotics;
  2.  
  3. import com.qualcomm.robotcore.eventloop.EventLoopManager;
  4. import com.qualcomm.robotcore.exception.RobotCoreException;
  5. import com.qualcomm.robotcore.hardware.ServoController;
  6. import com.qualcomm.robotcore.hardware.ServoController.PwmStatus;
  7. import com.qualcomm.robotcore.hardware.usb.RobotUsbDevice;
  8. import com.qualcomm.robotcore.util.Range;
  9. import com.qualcomm.robotcore.util.SerialNumber;
  10. import com.qualcomm.robotcore.util.TypeConversion;
  11.  
  12. class r
  13.   extends o
  14.   implements ServoController
  15. {
  16.   public static final byte[] a = { -1, 66, 67, 68, 69, 70, 71 };
  17.  
  18.   protected r(SerialNumber paramSerialNumber, RobotUsbDevice paramRobotUsbDevice, EventLoopManager paramEventLoopManager)
  19.     throws RobotCoreException, InterruptedException
  20.   {
  21.     super(paramSerialNumber, paramEventLoopManager, new s(paramSerialNumber, paramRobotUsbDevice, 9, 64, false));
  22.    
  23.     pwmDisable();
  24.   }
  25.  
  26.   public String getDeviceName()
  27.   {
  28.     return "Modern Robotics USB Servo Controller";
  29.   }
  30.  
  31.   public String getConnectionInfo()
  32.   {
  33.     return "USB " + getSerialNumber();
  34.   }
  35.  
  36.   public void close()
  37.   {
  38.     pwmDisable();
  39.     super.close();
  40.   }
  41.  
  42.   public void pwmEnable()
  43.   {
  44.     a(72, (byte)0);
  45.   }
  46.  
  47.   public void pwmDisable()
  48.   {
  49.     a(72, (byte)-1);
  50.   }
  51.  
  52.   public ServoController.PwmStatus getPwmStatus()
  53.   {
  54.     byte[] arrayOfByte = c(72, 1);
  55.     if (arrayOfByte[0] == -1) {
  56.       return ServoController.PwmStatus.DISABLED;
  57.     }
  58.     return ServoController.PwmStatus.ENABLED;
  59.   }
  60.  
  61.   public void setServoPosition(int channel, double position)
  62.   {
  63.     c(channel);
  64.     Range.throwIfRangeIsInvalid(position, 0.0D, 1.0D);
  65.    
  66.     a(a[channel], position * 240.0D);
  67.     pwmEnable();
  68.   }
  69.  
  70.   public double getServoPosition(int channel)
  71.   {
  72.     c(channel);
  73.    
  74.     byte[] arrayOfByte = c(a[channel], 1);
  75.    
  76.     return TypeConversion.unsignedByteToDouble(arrayOfByte[0]) / 240.0D;
  77.   }
  78.  
  79.   private void c(int paramInt)
  80.   {
  81.     if ((paramInt < 1) || (paramInt > a.length)) {
  82.       throw new IllegalArgumentException(String.format("Channel %d is invalid; valid channels are 1..%d", new Object[] {Integer.valueOf(paramInt), Integer.valueOf(6) }));
  83.     }
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement