Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #224 from Twinters007/startsWithA
Browse files Browse the repository at this point in the history
Ported 'a's to python
  • Loading branch information
virtuald committed Dec 6, 2016
2 parents b3102ce + b14bcb5 commit 5f915c0
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 92 deletions.
6 changes: 3 additions & 3 deletions wpilib/wpilib/adxl345_i2c.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2016-01-07 DS 376fc6b athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/ADXL345_I2C.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -63,8 +63,8 @@ def __init__(self, port, range, address=None):

self.setRange(range)

hal.HALReport(hal.HALUsageReporting.kResourceType_ADXL345,
hal.HALUsageReporting.kADXL345_I2C)
hal.report(hal.UsageReporting.kResourceType_ADXL345,
hal.UsageReporting.kADXL345_I2C)

LiveWindow.addSensor("ADXL345_I2C", port, self)

Expand Down
6 changes: 3 additions & 3 deletions wpilib/wpilib/adxl345_spi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-31 DS 6d854af athena/java/edu/wpi/first/wpilibj/ADXL345_SPI.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/ADXL345_SPI.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -69,8 +69,8 @@ def __init__(self, port, range):

self.setRange(range)

hal.HALReport(hal.HALUsageReporting.kResourceType_ADXL345,
hal.HALUsageReporting.kADXL345_SPI)
hal.report(hal.UsageReporting.kResourceType_ADXL345,
hal.UsageReporting.kADXL345_SPI)

LiveWindow.addSensor("ADXL345_SPI", port, self)

Expand Down
4 changes: 2 additions & 2 deletions wpilib/wpilib/adxl362.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-31 DS 9e18330 athena/java/edu/wpi/first/wpilibj/ADXL362.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/ADXL362.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, range, port=None):
self.spi.write([self.kRegWrite, self.kPowerCtlRegister,
self.kPowerCtl_Measure | self.kPowerCtl_UltraLowNoise])

hal.HALReport(hal.HALUsageReporting.kResourceType_ADXL362,
hal.report(hal.UsageReporting.kResourceType_ADXL362,
port)

LiveWindow.addSensor("ADXL362", port, self)
Expand Down
6 changes: 3 additions & 3 deletions wpilib/wpilib/adxrs450_gyro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2016-01-07 DS 628811e athena/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/ADXRS450_Gyro.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2015. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -72,12 +72,12 @@ def __init__(self, port=None):
DriverStation.reportError("could not find ADXRS450 gyro on SPI port %s" % port, False)
return

self.spi.initAccumulator(self.kSamplePeriod, 0x20000000, 4, 0x0c000000, 0x04000000,
self.spi.initAccumulator(self.kSamplePeriod, 0x20000000, 4, 0x0c00000e, 0x04000000,
10, 16, True, True)

self.calibrate()

hal.HALReport(hal.HALUsageReporting.kResourceType_ADXRS450, port)
hal.report(hal.UsageReporting.kResourceType_ADXRS450, port)
LiveWindow.addSensor("ADXRS450_Gyro", port, self)

def calibrate(self):
Expand Down
4 changes: 2 additions & 2 deletions wpilib/wpilib/analogaccelerometer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-24 DS 6d854af athena/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogAccelerometer.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(self, channel):
self.voltsPerG = 1.0
self.zeroGVoltage = 2.5
self.pidSource = self.PIDSourceType.kDisplacement
hal.HALReport(hal.HALUsageReporting.kResourceType_Accelerometer,
hal.report(hal.UsageReporting.kResourceType_Accelerometer,
self.analogChannel.getChannel())
LiveWindow.addSensorChannel("Accelerometer",
self.analogChannel.getChannel(), self)
Expand Down
82 changes: 26 additions & 56 deletions wpilib/wpilib/analoggyro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2016-01-07 DS 628811e athena/java/edu/wpi/first/wpilibj/AnalogGyro.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogGyro.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -37,7 +37,7 @@ class AnalogGyro(GyroBase):
kDefaultVoltsPerDegreePerSecond = 0.007

PIDSourceType = PIDSource.PIDSourceType

def __init__(self, channel, center=None, offset=None):
"""Gyro constructor.
Expand All @@ -56,6 +56,7 @@ def __init__(self, channel, center=None, offset=None):
:param offset: Preset uncalibrated value to use as the gyro offset
:type offset: float
"""

if not hasattr(channel, "initAccumulator"):
channel = AnalogInput(channel)
self.channelAllocated = True
Expand All @@ -64,101 +65,71 @@ def __init__(self, channel, center=None, offset=None):

self.analog = channel

self.voltsPerDegreePerSecond = AnalogGyro.kDefaultVoltsPerDegreePerSecond
self.analog.setAverageBits(AnalogGyro.kAverageBits)
self.analog.setOversampleBits(AnalogGyro.kOversampleBits)
sampleRate = AnalogGyro.kSamplesPerSecond \
* (1 << (AnalogGyro.kAverageBits + AnalogGyro.kOversampleBits))
AnalogInput.setGlobalSampleRate(sampleRate)
if not hal.HALIsSimulation():
Timer.delay(1.0)

self.gyroHandle = hal.initializeAnalogGyro(self.analog.port)


self.setDeadband(0.0)

self.setPIDSourceType(self.PIDSourceType.kDisplacement)
hal.setupAnalogGyro(self.gyroHandle)

hal.HALReport(hal.HALUsageReporting.kResourceType_Gyro,
hal.report(hal.UsageReporting.kResourceType_Gyro,
self.analog.getChannel())
LiveWindow.addSensorChannel("AnalogGyro", self.analog.getChannel(), self)

if center is None or offset is None:
self.calibrate()
else:
self.center = int(center)
self.offset = float(offset)
self.analog.setAccumulatorCenter(self.center)
self.analog.resetAccumulator()


hal.setAnalogGyroParameters(self.gyroHandle, self.kDefaultVoltsPerDegreePerSecond, offset, center)
self.reset()


def calibrate(self):
""":see: :meth:`.Gyro.calibrate`"""
self.analog.initAccumulator()
self.analog.resetAccumulator()
hal.calibrateAnalogGyro(self.gyroHandle)

# Only do this on a real robot
if not hal.HALIsSimulation():
Timer.delay(AnalogGyro.kCalibrationSampleTime)

value, count = self.analog.getAccumulatorOutput()

self.center = int(float(value) / float(count) + .5)

self.offset = (float(value) / float(count)) - self.center

self.analog.setAccumulatorCenter(self.center)
self.analog.resetAccumulator()

def reset(self):
""":see: :meth:`.Gyro.reset`"""
if self.analog is not None:
self.analog.resetAccumulator()
hal.resetAnalogGyro(self.gyroHandle)

def free(self):
""":see: :meth:`.Gyro.free`"""
LiveWindow.removeComponent(self)
if self.analog is not None and self.channelAllocated:
self.analog.free()
self.analog = None

hal.freeAnalogGyro(self.gyroHandle)
self.gyroHandle = 0

def getAngle(self):
""":see: :meth:`.Gyro.getAngle`"""

if self.analog is None:
return 0.0
value, count = self.analog.getAccumulatorOutput()

value -= count * self.offset

return (value
* 1e-9
* self.analog.getLSBWeight()
* (1 << self.analog.getAverageBits())
/ (AnalogInput.getGlobalSampleRate() * self.voltsPerDegreePerSecond))

return hal.getAnalogGyroAngle(self.gyroHandle)

def getRate(self):
""":see: :meth:`.Gyro.getRate`"""
if self.analog is None:
return 0.0
else:
return ((self.analog.getAverageValue() - (self.center + self.offset))
* 1e-9
* self.analog.getLSBWeight()
/ ((1 << self.analog.getOversampleBits()) * self.voltsPerDegreePerSecond))
return hal.getAnalogGyroRate(self.gyroHandle)

def getOffset(self):
"""Return the gyro offset value set during calibration to
use as a future preset
:returns: the current offset value
"""
return self.offset
return hal.getAnalogGyroOffset(self.gyroHandle)

def getCenter(self):
"""Return the gyro center value set during calibration to
use as a future preset
:returns: the current center value
"""
return self.center
return hal.getAnalogGyroCenter(self.gyroHandle)

def setSensitivity(self, voltsPerDegreePerSecond):
"""Set the gyro sensitivity. This takes the number of
Expand All @@ -170,7 +141,7 @@ def setSensitivity(self, voltsPerDegreePerSecond):
The sensitivity in Volts/degree/second
:type voltsPerDegreePerSecond: float
"""
self.voltsPerDegreePerSecond = voltsPerDegreePerSecond
hal.setAnalogGyroVoltsPerDegreePerSecond(self.gyroHandle, voltsPerDegreePerSecond)

def setDeadband(self, volts):
"""Set the size of the neutral zone. Any voltage from the gyro less
Expand All @@ -183,7 +154,6 @@ def setDeadband(self, volts):
"""
if self.analog is None:
return
deadband = int(volts * 1e9 / self.analog.getLSBWeight() *
(1 << self.analog.getOversampleBits()))
self.analog.setAccumulatorDeadband(deadband)

hal.setAnalogGyroDeadband(self.gyroHandle, volts)

14 changes: 5 additions & 9 deletions wpilib/wpilib/analoginput.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-28 DS 375a195 athena/java/edu/wpi/first/wpilibj/AnalogInput.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogInput.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -46,13 +46,9 @@ def __init__(self, channel):
"""Construct an analog channel.
:param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
"""
if not hal.checkAnalogInputChannel(channel):
raise IndexError("Analog input channel %d cannot be allocated. Channel is not present." % channel)
try:
AnalogInput.channels.allocate(self, channel)
except IndexError as e:
raise IndexError("Analog input channel %d is already allocated" % channel) from e


SensorBase.checkAnalogInputChannel(channel)

self.channel = channel
self.accumulatorOffset = 0
self.pidSource = self.PIDSourceType.kDisplacement
Expand All @@ -61,7 +57,7 @@ def __init__(self, channel):
self._port = hal.initializeAnalogInputPort(port)

LiveWindow.addSensorChannel("AnalogInput", channel, self)
hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
hal.report(hal.UsageReporting.kResourceType_AnalogChannel,
channel)

self.__finalizer = weakref.finalize(self, _freeAnalogInput, self._port)
Expand Down
13 changes: 4 additions & 9 deletions wpilib/wpilib/analogoutput.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-24 DS de39877 athena/java/edu/wpi/first/wpilibj/AnalogOutput.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogOutput.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2014. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -28,20 +28,15 @@ def __init__(self, channel):
:param channel: The channel number to represent.
"""
if not hal.checkAnalogOutputChannel(channel):
raise IndexError("Analog output channel %d cannot be allocated. Channel is not present." % channel)
try:
AnalogOutput.channels.allocate(self, channel)
except IndexError as e:
raise IndexError("Analog output channel %d is already allocated" % channel) from e

SensorBase.checkAnalogOutputChannel(channel)

self.channel = channel

port = hal.getPort(channel)
self._port = hal.initializeAnalogOutputPort(port)

LiveWindow.addSensorChannel("AnalogOutput", channel, self)
hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
hal.report(hal.UsageReporting.kResourceType_AnalogChannel,
channel, 1)

self.__finalizer = weakref.finalize(self, _freeAnalogOutput, self._port)
Expand Down
2 changes: 1 addition & 1 deletion wpilib/wpilib/analogpotentiometer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-24 DS 6d854af athena/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogPotentiometer.java
#----------------------------------------------------------------------------*/
# Copyright (c) FIRST 2008-2014. All Rights Reserved. */
# Open Source Software - may be modified and shared by FRC teams. The code */
Expand Down
8 changes: 6 additions & 2 deletions wpilib/wpilib/analogtrigger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-24 DS 6d854af athena/java/edu/wpi/first/wpilibj/AnalogTrigger.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogTrigger.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -44,6 +44,7 @@ def __init__(self, channel):
"""
if hasattr(channel, "getChannel"):
channel = channel.getChannel()
self.analogInput = channel

port = hal.getPort(channel)
self._port, self.index = hal.initializeAnalogTrigger(port)
Expand All @@ -53,7 +54,7 @@ def __init__(self, channel):
# Need this to free on unit test wpilib reset
Resource._add_global_resource(self)

hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogTrigger,
hal.report(hal.UsageReporting.kResourceType_AnalogTrigger,
channel)

@property
Expand All @@ -65,6 +66,9 @@ def port(self):
def free(self):
"""Release the resources used by this object"""
self.__finalizer()
if self.analogInput:
self.analogInput.free()


def setLimitsRaw(self, lower, upper):
"""Set the upper and lower limits of the analog trigger. The limits are
Expand Down
4 changes: 2 additions & 2 deletions wpilib/wpilib/analogtriggeroutput.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# validated: 2015-12-24 DS 6d854af athena/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java
# validated: 2016-12-03 TW e44a6e227a89 athena/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2012. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, trigger, outputType):
self.trigger = trigger
self.outputType = outputType

hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogTriggerOutput,
hal.report(hal.UsageReporting.kResourceType_AnalogTriggerOutput,
trigger.index, outputType)

def free(self):
Expand Down

0 comments on commit 5f915c0

Please sign in to comment.