Permalink
...
Comparing changes
Open a pull request
- 6 commits
- 5 files changed
- 0 commit comments
- 3 contributors
Commits on Jan 17, 2015
|
|
computer-whisperer |
51f0c59
|
Commits on Jan 18, 2015
|
|
computer-whisperer |
18f9040
|
Commits on Jan 19, 2015
|
|
computer-whisperer |
b8efea4
|
Commits on Jan 20, 2015
|
|
virtuald |
39f41c6
|
Commits on Jan 21, 2015
|
|
virtuald |
d42b54f
|
|||
|
|
virtuald |
f45d9ca
|
Unified
Split
Showing
with
59 additions
and 55 deletions.
- +1 −1 hal-roborio/setup.py
- +1 −1 wpilib/setup.py
- +18 −18 wpilib/tests/test_robotdrive.py
- +11 −1 wpilib/wpilib/canjaguar.py
- +28 −34 wpilib/wpilib/robotdrive.py
View
2
hal-roborio/setup.py
| @@ -53,7 +53,7 @@ def _reporthook(count, blocksize, totalsize): | ||
| # Generate a new version.py if required | ||
| if not exists(version_file) or __version__ != version or __hal_version__ != hal_version: | ||
| - with open(join(setup_dir, base_package, 'version.py'), 'w') as fp: | ||
| + with open(version_file, 'w') as fp: | ||
| fp.write("# Autogenerated by setup.py\n__version__ = '{0}'\n__hal_version__ = '{1}'".format(version, hal_version)) | ||
View
2
wpilib/setup.py
| @@ -49,7 +49,7 @@ | ||
| url='https://github.com/robotpy/robotpy-wpilib', | ||
| keywords='frc first robotics wpilib', | ||
| packages=find_packages(), | ||
| - install_requires=['pynetworktables>=2015.0.4'], | ||
| + install_requires=['pynetworktables>=2015.0.6'], | ||
| license="BSD License", | ||
| classifiers=[ | ||
| "Development Status :: 5 - Production/Stable", | ||
View
36
wpilib/tests/test_robotdrive.py
| @@ -39,8 +39,8 @@ def test_init_two(kw, mc, wpimock, halmock): | ||
| assert drive.rearLeftMotor == left | ||
| assert drive.rearRightMotor == right | ||
| - left.set.assert_called_once_with(0.0, 0x80) | ||
| - right.set.assert_called_once_with(0.0, 0x80) | ||
| + left.set.assert_called_once_with(0.0, 0) | ||
| + right.set.assert_called_once_with(0.0, 0) | ||
| else: | ||
| if mc: | ||
| mclass = getattr(wpimock, mc) | ||
| @@ -99,10 +99,10 @@ def test_init_four(kw, mc, wpimock, halmock): | ||
| assert drive.frontRightMotor == fright | ||
| assert drive.rearRightMotor == rright | ||
| - fleft.set.assert_called_once_with(0.0, 0x80) | ||
| - rleft.set.assert_called_once_with(0.0, 0x80) | ||
| - fright.set.assert_called_once_with(0.0, 0x80) | ||
| - rright.set.assert_called_once_with(0.0, 0x80) | ||
| + fleft.set.assert_called_once_with(0.0, 0) | ||
| + rleft.set.assert_called_once_with(0.0, 0) | ||
| + fright.set.assert_called_once_with(0.0, 0) | ||
| + rright.set.assert_called_once_with(0.0, 0) | ||
| else: | ||
| if mc: | ||
| mclass = getattr(wpimock, mc) | ||
| @@ -407,19 +407,19 @@ def test_holonomicDrive(drive4): | ||
| def test_setLeftRightMotorOutputs(drive4): | ||
| drive4.feed = MagicMock() | ||
| drive4.setLeftRightMotorOutputs(0.2, 0.3) | ||
| - drive4.frontLeftMotor.set.assert_called_once_with(0.2, 0x80) | ||
| - drive4.rearLeftMotor.set.assert_called_once_with(0.2, 0x80) | ||
| - drive4.frontRightMotor.set.assert_called_once_with(-0.3, 0x80) | ||
| - drive4.rearRightMotor.set.assert_called_once_with(-0.3, 0x80) | ||
| + drive4.frontLeftMotor.set.assert_called_once_with(0.2, 0) | ||
| + drive4.rearLeftMotor.set.assert_called_once_with(0.2, 0) | ||
| + drive4.frontRightMotor.set.assert_called_once_with(-0.3, 0) | ||
| + drive4.rearRightMotor.set.assert_called_once_with(-0.3, 0) | ||
| assert drive4.feed.called | ||
| drive4.frontLeftMotor = None | ||
| drive4.frontRightMotor = None | ||
| drive4.rearLeftMotor.reset_mock() | ||
| drive4.rearRightMotor.reset_mock() | ||
| drive4.setLeftRightMotorOutputs(0.2, 0.3) | ||
| - drive4.rearLeftMotor.set.assert_called_once_with(0.2, 0x80) | ||
| - drive4.rearRightMotor.set.assert_called_once_with(-0.3, 0x80) | ||
| + drive4.rearLeftMotor.set.assert_called_once_with(0.2, 0) | ||
| + drive4.rearRightMotor.set.assert_called_once_with(-0.3, 0) | ||
| @pytest.mark.parametrize("motor", ["rearLeftMotor", "rearRightMotor"]) | ||
| def test_setLeftRightMotorOutputs_error(motor, drive4): | ||
| @@ -461,10 +461,10 @@ def test_setInvertedMotor(motor, drive4): | ||
| assert drive4.invertedMotors[motor] == 1 # not inverted | ||
| # drive to make sure it took effect | ||
| drive4.setLeftRightMotorOutputs(0.2, 0.3) | ||
| - drive4.frontLeftMotor.set.assert_called_once_with(0.2*drive4.invertedMotors[drive4.MotorType.kFrontLeft], 0x80) | ||
| - drive4.rearLeftMotor.set.assert_called_once_with(0.2*drive4.invertedMotors[drive4.MotorType.kRearLeft], 0x80) | ||
| - drive4.frontRightMotor.set.assert_called_once_with(-0.3*drive4.invertedMotors[drive4.MotorType.kFrontRight], 0x80) | ||
| - drive4.rearRightMotor.set.assert_called_once_with(-0.3*drive4.invertedMotors[drive4.MotorType.kRearRight], 0x80) | ||
| + drive4.frontLeftMotor.set.assert_called_once_with(0.2*drive4.invertedMotors[drive4.MotorType.kFrontLeft], 0) | ||
| + drive4.rearLeftMotor.set.assert_called_once_with(0.2*drive4.invertedMotors[drive4.MotorType.kRearLeft], 0) | ||
| + drive4.frontRightMotor.set.assert_called_once_with(-0.3*drive4.invertedMotors[drive4.MotorType.kFrontRight], 0) | ||
| + drive4.rearRightMotor.set.assert_called_once_with(-0.3*drive4.invertedMotors[drive4.MotorType.kRearRight], 0) | ||
| def test_setSensitivity(drive_lr): | ||
| drive_lr.setSensitivity(0.1) | ||
| @@ -478,8 +478,8 @@ def test_setMaxOutput(drive4): | ||
| assert drive4.maxOutput == 0.5 | ||
| # drive to make sure it took effect | ||
| drive4.setLeftRightMotorOutputs(1.0, 0.75) | ||
| - drive4.rearLeftMotor.set.assert_called_once_with(0.5, 0x80) | ||
| - drive4.rearRightMotor.set.assert_called_once_with(-0.375, 0x80) | ||
| + drive4.rearLeftMotor.set.assert_called_once_with(0.5, 0) | ||
| + drive4.rearRightMotor.set.assert_called_once_with(-0.375, 0) | ||
| def test_getDescription(drive_lr): | ||
| assert drive_lr.getDescription() == "Robot Drive" | ||
View
12
wpilib/wpilib/canjaguar.py
| @@ -78,6 +78,9 @@ def _sendMessageHelper(messageID, data, period): | ||
| def _freeJaguar(deviceNumber, controlMode): | ||
| # Cancel periodic messages to the Jaguar, effectively disabling it. | ||
| # Disable periodic setpoints | ||
| + | ||
| + CANJaguar.allocated.free(deviceNumber-1) | ||
| + | ||
| if controlMode == CANJaguar.ControlMode.PercentVbus: | ||
| messageID = deviceNumber | _cj.LM_API_VOLT_T_SET | ||
| elif controlMode == CANJaguar.ControlMode.Speed: | ||
| @@ -95,7 +98,7 @@ def _freeJaguar(deviceNumber, controlMode): | ||
| frccan.CAN_SEND_PERIOD_STOP_REPEATING) | ||
| data = _packFXP8_8(CANJaguar.kApproxBusVoltage) | ||
| - _sendMessageHelper(_cj.LM_API_CFG_MAX_VOUT | deviceNumber, data) | ||
| + _sendMessageHelper(_cj.LM_API_CFG_MAX_VOUT | deviceNumber, data, frccan.CAN_SEND_PERIOD_NO_REPEAT) | ||
| class CANJaguar(LiveWindowSendable, MotorSafety): | ||
| """Texas Instruments Jaguar Speed Controller as a CAN device.""" | ||
| @@ -304,6 +307,13 @@ def __init__(self, deviceNumber): | ||
| else: | ||
| DriverStation.reportError("Jag %d firmware %d is not FIRST approved (must be at least version 108 of the FIRST approved firmware)" % (self.deviceNumber, self.firmwareVersion), False) | ||
| + def free(self): | ||
| + """ | ||
| + Cancel periodic messages to the Jaguar, effectively disabling it. | ||
| + No other methods should be called after this is called. | ||
| + """ | ||
| + self._canjaguar_finalizer() | ||
| + | ||
| def getDeviceNumber(self): | ||
| """:returns: The CAN ID passed in the constructor | ||
| """ | ||
View
62
wpilib/wpilib/robotdrive.py
| @@ -13,7 +13,6 @@ | ||
| from .motorsafety import MotorSafety | ||
| from .talon import Talon | ||
| from .canjaguar import CANJaguar | ||
| -from hal import frccan | ||
| __all__ = ["RobotDrive"] | ||
| @@ -145,7 +144,7 @@ def __init__(self, *args, **kwargs): | ||
| self.maxOutput = RobotDrive.kDefaultMaxOutput | ||
| self.sensitivity = RobotDrive.kDefaultSensitivity | ||
| - self.isCANInitialized = False #Upstream: TODO Fix Can | ||
| + self.syncGroup = 0x0 | ||
| # set up motor safety | ||
| self.setExpiration(self.kDefaultExpirationTime) | ||
| @@ -463,18 +462,14 @@ def mecanumDrive_Cartesian(self, x, y, rotation, gyroAngle): | ||
| RobotDrive.normalize(wheelSpeeds) | ||
| - syncGroup = 0x80 | ||
| - self.frontLeftMotor.set(wheelSpeeds[self.MotorType.kFrontLeft] * self.invertedMotors[self.MotorType.kFrontLeft] * self.maxOutput, syncGroup) | ||
| - self.frontRightMotor.set(wheelSpeeds[self.MotorType.kFrontRight] * self.invertedMotors[self.MotorType.kFrontRight] * self.maxOutput, syncGroup) | ||
| - self.rearLeftMotor.set(wheelSpeeds[self.MotorType.kRearLeft] * self.invertedMotors[self.MotorType.kRearLeft] * self.maxOutput, syncGroup) | ||
| - self.rearRightMotor.set(wheelSpeeds[self.MotorType.kRearRight] * self.invertedMotors[self.MotorType.kRearRight] * self.maxOutput, syncGroup) | ||
| + self.frontLeftMotor.set(wheelSpeeds[self.MotorType.kFrontLeft] * self.invertedMotors[self.MotorType.kFrontLeft] * self.maxOutput, self.syncGroup) | ||
| + self.frontRightMotor.set(wheelSpeeds[self.MotorType.kFrontRight] * self.invertedMotors[self.MotorType.kFrontRight] * self.maxOutput, self.syncGroup) | ||
| + self.rearLeftMotor.set(wheelSpeeds[self.MotorType.kRearLeft] * self.invertedMotors[self.MotorType.kRearLeft] * self.maxOutput, self.syncGroup) | ||
| + self.rearRightMotor.set(wheelSpeeds[self.MotorType.kRearRight] * self.invertedMotors[self.MotorType.kRearRight] * self.maxOutput, self.syncGroup) | ||
| - if self.isCANInitialized: | ||
| - try: | ||
| - CANJaguar.updateSyncGroup(syncGroup) | ||
| - except frccan.CANNotInitializedException: | ||
| - self.isCANInitialized = False | ||
| + if self.syncGroup != 0: | ||
| + CANJaguar.updateSyncGroup(self.syncGroup) | ||
| self.feed() | ||
| def mecanumDrive_Polar(self, magnitude, direction, rotation): | ||
| @@ -512,18 +507,14 @@ def mecanumDrive_Polar(self, magnitude, direction, rotation): | ||
| RobotDrive.normalize(wheelSpeeds) | ||
| - syncGroup = 0x80 | ||
| - self.frontLeftMotor.set(wheelSpeeds[self.MotorType.kFrontLeft] * self.invertedMotors[self.MotorType.kFrontLeft] * self.maxOutput, syncGroup) | ||
| - self.frontRightMotor.set(wheelSpeeds[self.MotorType.kFrontRight] * self.invertedMotors[self.MotorType.kFrontRight] * self.maxOutput, syncGroup) | ||
| - self.rearLeftMotor.set(wheelSpeeds[self.MotorType.kRearLeft] * self.invertedMotors[self.MotorType.kRearLeft] * self.maxOutput, syncGroup) | ||
| - self.rearRightMotor.set(wheelSpeeds[self.MotorType.kRearRight] * self.invertedMotors[self.MotorType.kRearRight] * self.maxOutput, syncGroup) | ||
| + self.frontLeftMotor.set(wheelSpeeds[self.MotorType.kFrontLeft] * self.invertedMotors[self.MotorType.kFrontLeft] * self.maxOutput, self.syncGroup) | ||
| + self.frontRightMotor.set(wheelSpeeds[self.MotorType.kFrontRight] * self.invertedMotors[self.MotorType.kFrontRight] * self.maxOutput, self.syncGroup) | ||
| + self.rearLeftMotor.set(wheelSpeeds[self.MotorType.kRearLeft] * self.invertedMotors[self.MotorType.kRearLeft] * self.maxOutput, self.syncGroup) | ||
| + self.rearRightMotor.set(wheelSpeeds[self.MotorType.kRearRight] * self.invertedMotors[self.MotorType.kRearRight] * self.maxOutput, self.syncGroup) | ||
| - if self.isCANInitialized: | ||
| - try: | ||
| - CANJaguar.updateSyncGroup(syncGroup) | ||
| - except frccan.CANNotInitializedException: | ||
| - self.isCANInitialized = False | ||
| + if self.syncGroup != 0: | ||
| + CANJaguar.updateSyncGroup(self.syncGroup) | ||
| self.feed() | ||
| def holonomicDrive(self, magnitude, direction, rotation): | ||
| @@ -554,24 +545,19 @@ def setLeftRightMotorOutputs(self, leftOutput, rightOutput): | ||
| if self.rearLeftMotor is None or self.rearRightMotor is None: | ||
| raise ValueError("Null motor provided") | ||
| - syncGroup = 0x80 | ||
| - | ||
| leftOutput = RobotDrive.limit(leftOutput) * self.maxOutput | ||
| rightOutput = RobotDrive.limit(rightOutput) * self.maxOutput | ||
| if self.frontLeftMotor is not None: | ||
| - self.frontLeftMotor.set(leftOutput * self.invertedMotors[self.MotorType.kFrontLeft], syncGroup) | ||
| - self.rearLeftMotor.set(leftOutput * self.invertedMotors[self.MotorType.kRearLeft], syncGroup) | ||
| + self.frontLeftMotor.set(leftOutput * self.invertedMotors[self.MotorType.kFrontLeft], self.syncGroup) | ||
| + self.rearLeftMotor.set(leftOutput * self.invertedMotors[self.MotorType.kRearLeft], self.syncGroup) | ||
| if self.frontRightMotor is not None: | ||
| - self.frontRightMotor.set(-rightOutput * self.invertedMotors[self.MotorType.kFrontRight], syncGroup) | ||
| - self.rearRightMotor.set(-rightOutput * self.invertedMotors[self.MotorType.kRearRight], syncGroup) | ||
| - | ||
| - if self.isCANInitialized: | ||
| - try: | ||
| - CANJaguar.updateSyncGroup(syncGroup) | ||
| - except frccan.CANNotInitializedException: | ||
| - self.isCANInitialized = False | ||
| + self.frontRightMotor.set(-rightOutput * self.invertedMotors[self.MotorType.kFrontRight], self.syncGroup) | ||
| + self.rearRightMotor.set(-rightOutput * self.invertedMotors[self.MotorType.kRearRight], self.syncGroup) | ||
| + | ||
| + if self.syncGroup != 0: | ||
| + CANJaguar.updateSyncGroup(self.syncGroup) | ||
| self.feed() | ||
| @staticmethod | ||
| @@ -655,6 +641,14 @@ def getNumMotors(self): | ||
| if self.rearRightMotor is not None: motors += 1 | ||
| return motors | ||
| + def setCANJaguarSyncGroup(self, syncGroup): | ||
| + """ | ||
| + Set the number of the sync group for the motor controllers. If the motor controllers are :class:`CANJaguar`s, | ||
| + then they will be added to this sync group, causing them to update their values at the same time. | ||
| + | ||
| + :param syncGroup: The update group to add the motor controllers to. | ||
| + """ | ||
| + | ||
| def free(self): | ||
| self._RobotDrive_finalizer() | ||
| self.frontLeftMotor = None | ||