Squashed 'third_party/allwpilib_2016/' changes from 7f61816..3ce6feb
3ce6feb Updated release number for the new release
e054bbc This adds StopMotor() to the SpeedController interface for C++ and Java. For Java, this is as simple as just adding it, as all motors already have an implementation from MotorSafety that is correctly resolved. For C++, I had to override StopMotor in the classes that descend from SafePWM and explicitly call the SafePWM version. RobotDrive now calls StopMotor on each of its SpeedControllers, instead of calling Disable or setting the motor to 0.0 as it was doing previously.
a15b9dc Merge "More updates to the Gyro test fixing potential null pointer exception"
21b7213 Added Config routine to allow enabling/disabling of limit switch and soft limits. This improves upon the ConfigLimitMode routine, which does not allow certain combinations of enable/disabled limit features. Also keeps parity with LV and Java.
1b45237 Merge "Add an additional member variable for "stopped" which indicates the CAN motor controller has been explicitly stopped, but not disabled by the user (main use case is MotorSafety tripping). When Set() is called the next time the controller will be re-enabled automatically."
1096b15 Add an additional member variable for "stopped" which indicates the CAN motor controller has been explicitly stopped, but not disabled by the user (main use case is MotorSafety tripping). When Set() is called the next time the controller will be re-enabled automatically.
7da21fa More updates to the Gyro test fixing potential null pointer exception
ede5862 Rate-limit duplicate error messages to avoid flooding console.
c22284d Merge "artf4818: Fix CAN Talon JNI references with underscores."
cac3741 Merge "Updated PDP port of Talon and disabled PDP tests for Victor and Jaguar since the Victor and Jaguar don't draw enough current for the PDP to read above 0. PDP tests for both java and cpp only test the Talon now."
097aa8c Fixed the gyro deviation over time test
1d647b3 artf4818: Fix CAN Talon JNI references with underscores.
368cfc7 Merge "Fixed the motor tests by reducing speed to within the limits of the encoders we use. Also fixed java pid tolerances since getAvgError() was broken. It is now fixed and works properly. Added tests for both java and cpp that test if pid tolerances are working using fake input output pairs."
833e459 Updated PDP port of Talon and disabled PDP tests for Victor and Jaguar since the Victor and Jaguar don't draw enough current for the PDP to read above 0. PDP tests for both java and cpp only test the Talon now.
6c096a3 Fixed the motor tests by reducing speed to within the limits of the encoders we use. Also fixed java pid tolerances since getAvgError() was broken. It is now fixed and works properly. Added tests for both java and cpp that test if pid tolerances are working using fake input output pairs.
dd7eb0f Fixed robot drive for C++ Simulation
258a622 Merge "Update version number for Release 3 Print distinctive message on robot program startup Change-Id: Ic91b81bd298ee6730503933cf0e733702e4b4405"
b1386c6 Update version number for Release 3 Print distinctive message on robot program startup Change-Id: Ic91b81bd298ee6730503933cf0e733702e4b4405
a58de40 Merge "Removed publishing of java sim jar"
792d0d3 PDP Classes should support any PDP address
35df955 Merge "Remove maven local as a possible search location"
a0ce9ee Another improvement to HAL-joy getting to ensure it works in future RIO image updates.
0f02c31 Removed publishing of java sim jar
8435ac7 DriverStation::GetJoystickName(): Make work for stick>0.
b4cf4f4 Remove maven local as a possible search location
c3000c3 Merge "Fix HALGetJoystickDescriptor()."
4dec0b4 Merge "Fixed Simulation C++ API"
abc9c27 Fixed Simulation C++ API
b8ae9ec Fix HALGetJoystickDescriptor().
a60f874 Artf4800: Fixes HALGetJoystick*** Segfault
010b584 Merge "fix sim_ds launch script"
4429e16 Merge "Added build dir specification for sim javadoc to not overwrite athena javadoc"
ec9349b Initialized the m_sensors variable to fix artf4798.
9745af8 Added build dir specification for sim javadoc to not overwrite athena javadoc
4da8702 fix sim_ds launch script
05acf79 Fix C++ PIDController SetToleranceBuffer and OnTarget locking.
94a6b05 Merge "Fix onTarget() so that it returns false until there are any values retrieved"
d06053d Fix onTarget() so that it returns false until there are any values retrieved
74927cc Correctly set smart dashboard type for AnalogGyro and ADXRS450_Gyro.
070752f Merge "Fixed sim_ds script library path"
21a8bab Merge "PIDController feed forward term can now be calculated by the end user"
56bd6da Fixed sim_ds script library path
07710f1 Merge "Fixing install script... again"
e1cb61f Use absolute path for NT persistent storage.
09c7482 Fixing install script... again
a3b8bec PIDController feed forward term can now be calculated by the end user
790adb0 artf2612: Update license in source files.
042671c Merge "Removed gz_msgs from wpilibcSim"
c111690 Ultrasonic: replace linked list with std::set.
d71a8ed Removed gz_msgs from wpilibcSim
37259f7 Merge "Replaced linked list in Notifier with std::list"
cd17e7a Merge "Renamed Gyro to AnalogGyro to match athena API"
c5c8a87 Replaced linked list in Notifier with std::list
89405d8 Renamed Gyro to AnalogGyro to match athena API
4a19490 Merge "Adds CANTalon to LiveWindow"
c4a3567 Merge "Fixing the frcsim installer script"
295648f Adds CANTalon to LiveWindow
1b964a2 Merge "Fixes CAN devices in C++ library not showing in the livewindow"
7ba5cee Merge "HAL: Use extern "C" in implementation files."
d17d242 Fixes CAN devices in C++ library not showing in the livewindow
25a771a Added linear digital filters
7349c2c Fixing the frcsim installer script
c82122c Merge "Default bufLength for PIDController in Java should be 1"
58f3f97 Merge "Adds WaitResult to Java waitForInterrupt"
bc8ed12 HAL: Use extern "C" in implementation files.
4cac89e Default bufLength for PIDController in Java should be 1
64fcdcc Keep track of FPGA time rollovers with 64-bit time.
d30b283 Merge "Change C++ Notifier to allow std::function callback."
6ee3052 Merge "Rewrite C++ Notifier to use HAL multi-notifier support."
f5d09e2 Merge "Rewrite Java Notifier and update Interrupt JNI."
d0274aa Merge "Readded styleguide accidentally removed in the reorg"
68311ad Merge "Artf4179: Allow alternate I2C addresses for ADXL345_I2C"
dee12d4 Readded styleguide accidentally removed in the reorg
fa100df Fixed some typos in the comments of MotorEncoderFixture.java, a method name in CANMotorEncoderFixture.java, and the README files
3397b5c Adds WaitResult to Java waitForInterrupt
5f0dffd Artf4177: Use read byte count for ReadString
8564f33 Artf4179: Allow alternate I2C addresses for ADXL345_I2C
e52b52d Change C++ Notifier to allow std::function callback.
40b29e7 Rewrite C++ Notifier to use HAL multi-notifier support.
d126f45 Rewrite Java Notifier and update Interrupt JNI.
557805a Merge "finishing up FRCSim installer"
911b64b finishing up FRCSim installer
e24fe6f Merge "Artf4776 Fixes First DIO PWM usage errors"
f8f9284 Merge "Artf4774 Fixes HAL getHALErrorMessage missing error"
84428d5 Merge "Prevent double free in DigitalGlitchFilter"
a00a5ff Merge "Set correct error message"
9aeee98 Prevent double free in DigitalGlitchFilter
5d2186c working on install process for FRCSim 2016
7fdb616 Merge "This commit adds documentation generation, including grabbing ntcore sources, for both Java and C++. This will need changes made in the wpilib promotion tasks to copy the generatd documentation to the correct places."
f67ebca Improved READMEs
8a7c019 Artf4776 Fixes First DIO PWM usage errors
1cd2f9a Added libnipalu to make vision programs link properly
375b92a This commit adds documentation generation, including grabbing ntcore sources, for both Java and C++. This will need changes made in the wpilib promotion tasks to copy the generatd documentation to the correct places.
8d0a990 Set correct error message
b65401f Artf4774 Fixes HAL getHALErrorMessage missing error
5f918be Condition java sim build on -PmakeSim flag
53bd180 Merge "Add SPARK and SD540 motor controllers"
66cbe69 Fixed double free of DriverStation.
431f345 Repaired simulation build on linux
611593c Add Cmake wrappers and unzip desktop ntcore builds
51a18cd Add SPARK and SD540 motor controllers
c05e883 Merge changes I55ce71c6,I803680c1
2b80029 Rewrite CANTalon JNI layer.
ef4c45b Last feature addition for CANTalon java/C++ user-facing API.
Change-Id: Ia3a124978a426991890b6f8abbe07d34d75ba38d
git-subtree-dir: third_party/allwpilib_2016
git-subtree-split: 3ce6feb8acdeca46e93a55280fb6ace3a4d5bcd6
diff --git a/wpilibc/simulation/src/Joystick.cpp b/wpilibc/simulation/src/Joystick.cpp
index a7a299c..3c32e86 100644
--- a/wpilibc/simulation/src/Joystick.cpp
+++ b/wpilibc/simulation/src/Joystick.cpp
@@ -1,16 +1,15 @@
/*----------------------------------------------------------------------------*/
-/* Copyright (c) FIRST 2008. All Rights Reserved.
- */
+/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
-/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
+/* must be accompanied by the FIRST BSD license file in the root directory of */
+/* the project. */
/*----------------------------------------------------------------------------*/
#include "Joystick.h"
#include "DriverStation.h"
-//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include <math.h>
-#include <string.h>
+#include <memory>
const uint32_t Joystick::kDefaultXAxis;
const uint32_t Joystick::kDefaultYAxis;
@@ -26,21 +25,19 @@
* Construct an instance of a joystick.
* The joystick index is the usb port on the drivers station.
*
- * @param port The port on the driver station that the joystick is plugged into
- * (0-5).
+ * @param port The port on the driver station that the joystick is plugged into.
*/
Joystick::Joystick(uint32_t port)
- : Joystick(port, kNumAxisTypes, kNumButtonTypes) {
- m_axes[kXAxis] = kDefaultXAxis;
- m_axes[kYAxis] = kDefaultYAxis;
- m_axes[kZAxis] = kDefaultZAxis;
- m_axes[kTwistAxis] = kDefaultTwistAxis;
- m_axes[kThrottleAxis] = kDefaultThrottleAxis;
+ : Joystick(port, kNumAxisTypes, kNumButtonTypes)
+{
+ m_axes[kXAxis] = kDefaultXAxis;
+ m_axes[kYAxis] = kDefaultYAxis;
+ m_axes[kZAxis] = kDefaultZAxis;
+ m_axes[kTwistAxis] = kDefaultTwistAxis;
+ m_axes[kThrottleAxis] = kDefaultThrottleAxis;
- m_buttons[kTriggerButton] = kDefaultTriggerButton;
- m_buttons[kTopButton] = kDefaultTopButton;
-
- HALReport(HALUsageReporting::kResourceType_Joystick, port);
+ m_buttons[kTriggerButton] = kDefaultTriggerButton;
+ m_buttons[kTopButton] = kDefaultTopButton;
}
/**
@@ -53,108 +50,111 @@
* @param numAxisTypes The number of axis types in the enum.
* @param numButtonTypes The number of button types in the enum.
*/
-Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
- uint32_t numButtonTypes)
- : m_ds(DriverStation::GetInstance()),
- m_port(port),
- m_axes(numAxisTypes),
- m_buttons(numButtonTypes) {
- if (!joySticksInitialized) {
- for (auto& joystick : joysticks) joystick = nullptr;
- joySticksInitialized = true;
- }
- if (m_port >= DriverStation::kJoystickPorts) {
- wpi_setWPIError(BadJoystickIndex);
- } else {
- joysticks[m_port] = this;
- }
+Joystick::Joystick(uint32_t port, uint32_t numAxisTypes, uint32_t numButtonTypes)
+ : m_port (port),
+ m_ds(DriverStation::GetInstance())
+{
+ if ( !joySticksInitialized )
+ {
+ for (unsigned i = 0; i < DriverStation::kJoystickPorts; i++)
+ joysticks[i] = nullptr;
+ joySticksInitialized = true;
+ }
+ joysticks[m_port] = this;
+
+ m_axes = std::make_unique<uint32_t[]>(numAxisTypes);
+ m_buttons = std::make_unique<uint32_t[]>(numButtonTypes);
}
-Joystick *Joystick::GetStickForPort(uint32_t port) {
- Joystick *stick = joysticks[port];
- if (stick == nullptr) {
- stick = new Joystick(port);
- joysticks[port] = stick;
- }
- return stick;
+Joystick * Joystick::GetStickForPort(uint32_t port)
+{
+ Joystick *stick = joysticks[port];
+ if (stick == nullptr)
+ {
+ stick = new Joystick(port);
+ joysticks[port] = stick;
+ }
+ return stick;
}
/**
* Get the X value of the joystick.
* This depends on the mapping of the joystick connected to the current port.
- * @param hand This parameter is ignored for the Joystick class and is only here
- * to complete the GenericHID interface.
*/
-float Joystick::GetX(JoystickHand hand) const {
- return GetRawAxis(m_axes[kXAxis]);
+float Joystick::GetX(JoystickHand hand) const
+{
+ return GetRawAxis(m_axes[kXAxis]);
}
/**
* Get the Y value of the joystick.
* This depends on the mapping of the joystick connected to the current port.
- * @param hand This parameter is ignored for the Joystick class and is only here
- * to complete the GenericHID interface.
*/
-float Joystick::GetY(JoystickHand hand) const {
- return GetRawAxis(m_axes[kYAxis]);
+float Joystick::GetY(JoystickHand hand) const
+{
+ return GetRawAxis(m_axes[kYAxis]);
}
/**
* Get the Z value of the current joystick.
* This depends on the mapping of the joystick connected to the current port.
*/
-float Joystick::GetZ() const { return GetRawAxis(m_axes[kZAxis]); }
+float Joystick::GetZ() const
+{
+ return GetRawAxis(m_axes[kZAxis]);
+}
/**
* Get the twist value of the current joystick.
* This depends on the mapping of the joystick connected to the current port.
*/
-float Joystick::GetTwist() const { return GetRawAxis(m_axes[kTwistAxis]); }
+float Joystick::GetTwist() const
+{
+ return GetRawAxis(m_axes[kTwistAxis]);
+}
/**
* Get the throttle value of the current joystick.
* This depends on the mapping of the joystick connected to the current port.
*/
-float Joystick::GetThrottle() const {
- return GetRawAxis(m_axes[kThrottleAxis]);
+float Joystick::GetThrottle() const
+{
+ return GetRawAxis(m_axes[kThrottleAxis]);
}
/**
* Get the value of the axis.
*
- * @param axis The axis to read, starting at 0.
+ * @param axis The axis to read [1-6].
* @return The value of the axis.
*/
-float Joystick::GetRawAxis(uint32_t axis) const {
- return m_ds.GetStickAxis(m_port, axis);
+float Joystick::GetRawAxis(uint32_t axis) const
+{
+ return m_ds.GetStickAxis(m_port, axis);
}
/**
* For the current joystick, return the axis determined by the argument.
*
- * This is for cases where the joystick axis is returned programatically,
- * otherwise one of the
+ * This is for cases where the joystick axis is returned programatically, otherwise one of the
* previous functions would be preferable (for example GetX()).
*
* @param axis The axis to read.
* @return The value of the axis.
*/
-float Joystick::GetAxis(AxisType axis) const {
- switch (axis) {
- case kXAxis:
- return this->GetX();
- case kYAxis:
- return this->GetY();
- case kZAxis:
- return this->GetZ();
- case kTwistAxis:
- return this->GetTwist();
- case kThrottleAxis:
- return this->GetThrottle();
- default:
- wpi_setWPIError(BadJoystickAxis);
- return 0.0;
- }
+float Joystick::GetAxis(AxisType axis) const
+{
+ switch(axis)
+ {
+ case kXAxis: return this->GetX();
+ case kYAxis: return this->GetY();
+ case kZAxis: return this->GetZ();
+ case kTwistAxis: return this->GetTwist();
+ case kThrottleAxis: return this->GetThrottle();
+ default:
+ wpi_setWPIError(BadJoystickAxis);
+ return 0.0;
+ }
}
/**
@@ -162,12 +162,12 @@
*
* Look up which button has been assigned to the trigger and read its state.
*
- * @param hand This parameter is ignored for the Joystick class and is only here
- * to complete the GenericHID interface.
+ * @param hand This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
* @return The state of the trigger.
*/
-bool Joystick::GetTrigger(JoystickHand hand) const {
- return GetRawButton(m_buttons[kTriggerButton]);
+bool Joystick::GetTrigger(JoystickHand hand) const
+{
+ return GetRawButton(m_buttons[kTriggerButton]);
}
/**
@@ -175,45 +175,45 @@
*
* Look up which button has been assigned to the top and read its state.
*
- * @param hand This parameter is ignored for the Joystick class and is only here
- * to complete the GenericHID interface.
+ * @param hand This parameter is ignored for the Joystick class and is only here to complete the GenericHID interface.
* @return The state of the top button.
*/
-bool Joystick::GetTop(JoystickHand hand) const {
- return GetRawButton(m_buttons[kTopButton]);
+bool Joystick::GetTop(JoystickHand hand) const
+{
+ return GetRawButton(m_buttons[kTopButton]);
}
/**
* This is not supported for the Joystick.
* This method is only here to complete the GenericHID interface.
*/
-bool Joystick::GetBumper(JoystickHand hand) const {
- // Joysticks don't have bumpers.
- return false;
+bool Joystick::GetBumper(JoystickHand hand) const
+{
+ // Joysticks don't have bumpers.
+ return false;
}
/**
- * Get the button value (starting at button 1)
+ * Get the button value for buttons 1 through 12.
*
- * The buttons are returned in a single 16 bit value with one bit representing
- * the state
+ * The buttons are returned in a single 16 bit value with one bit representing the state
* of each button. The appropriate button is returned as a boolean value.
*
- * @param button The button number to be read (starting at 1)
+ * @param button The button number to be read.
* @return The state of the button.
**/
-bool Joystick::GetRawButton(uint32_t button) const {
- return m_ds.GetStickButton(m_port, button);
+bool Joystick::GetRawButton(uint32_t button) const
+{
+ return m_ds.GetStickButton(m_port, button);
}
/**
- * Get the state of a POV on the joystick.
- *
- * @param pov The index of the POV to read (starting at 0)
- * @return the angle of the POV in degrees, or -1 if the POV is not pressed.
- */
+* Get the state of a POV on the joystick.
+*
+* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
+*/
int Joystick::GetPOV(uint32_t pov) const {
- return m_ds.GetStickPOV(m_port, pov);
+ return 0; // TODO
}
/**
@@ -224,75 +224,27 @@
* @param button The type of button to read.
* @return The state of the button.
*/
-bool Joystick::GetButton(ButtonType button) const {
- switch (button) {
- case kTriggerButton:
- return GetTrigger();
- case kTopButton:
- return GetTop();
- default:
- return false;
- }
+bool Joystick::GetButton(ButtonType button) const
+{
+ switch (button)
+ {
+ case kTriggerButton: return GetTrigger();
+ case kTopButton: return GetTop();
+ default:
+ return false;
+ }
}
/**
- * Get the number of axis for a joystick
- *
- * @return the number of axis for the current joystick
- */
-int Joystick::GetAxisCount() const { return m_ds.GetStickAxisCount(m_port); }
-
-/**
- * Get the value of isXbox for the joystick.
- *
- * @return A boolean that is true if the joystick is an xbox controller.
- */
-bool Joystick::GetIsXbox() const { return m_ds.GetJoystickIsXbox(m_port); }
-
-/**
- * Get the HID type of the controller.
- *
- * @return the HID type of the controller.
- */
-Joystick::HIDType Joystick::GetType() const {
- return static_cast<HIDType>(m_ds.GetJoystickType(m_port));
-}
-
-/**
- * Get the name of the joystick.
- *
- * @return the name of the controller.
- */
-std::string Joystick::GetName() const { return m_ds.GetJoystickName(m_port); }
-
-// int Joystick::GetAxisType(uint8_t axis) const
-//{
-// return m_ds.GetJoystickAxisType(m_port, axis);
-//}
-
-/**
- * Get the number of axis for a joystick
- *
-* @return the number of buttons on the current joystick
- */
-int Joystick::GetButtonCount() const {
- return m_ds.GetStickButtonCount(m_port);
-}
-
-/**
- * Get the number of axis for a joystick
- *
- * @return then umber of POVs for the current joystick
- */
-int Joystick::GetPOVCount() const { return m_ds.GetStickPOVCount(m_port); }
-
-/**
* Get the channel currently associated with the specified axis.
*
* @param axis The axis to look up the channel for.
* @return The channel fr the axis.
*/
-uint32_t Joystick::GetAxisChannel(AxisType axis) const { return m_axes[axis]; }
+uint32_t Joystick::GetAxisChannel(AxisType axis)
+{
+ return m_axes[axis];
+}
/**
* Set the channel associated with a specified axis.
@@ -300,8 +252,9 @@
* @param axis The axis to set the channel for.
* @param channel The channel to set the axis to.
*/
-void Joystick::SetAxisChannel(AxisType axis, uint32_t channel) {
- m_axes[axis] = channel;
+void Joystick::SetAxisChannel(AxisType axis, uint32_t channel)
+{
+ m_axes[axis] = channel;
}
/**
@@ -311,7 +264,7 @@
* @return The magnitude of the direction vector
*/
float Joystick::GetMagnitude() const {
- return sqrt(pow(GetX(), 2) + pow(GetY(), 2));
+ return sqrt(pow(GetX(),2) + pow(GetY(),2) );
}
/**
@@ -320,58 +273,19 @@
*
* @return The direction of the vector in radians
*/
-float Joystick::GetDirectionRadians() const { return atan2(GetX(), -GetY()); }
+float Joystick::GetDirectionRadians() const {
+ return atan2(GetX(), -GetY());
+}
/**
* Get the direction of the vector formed by the joystick and its origin
* in degrees
*
- * uses acos(-1) to represent Pi due to absence of readily accessible Pi
+ * uses acos(-1) to represent Pi due to absence of readily accessable Pi
* constant in C++
*
* @return The direction of the vector in degrees
*/
float Joystick::GetDirectionDegrees() const {
- return (180 / acos(-1)) * GetDirectionRadians();
-}
-
-/**
- * Set the rumble output for the joystick. The DS currently supports 2 rumble
- * values,
- * left rumble and right rumble
- * @param type Which rumble value to set
- * @param value The normalized value (0 to 1) to set the rumble to
- */
-void Joystick::SetRumble(RumbleType type, float value) {
- if (value < 0)
- value = 0;
- else if (value > 1)
- value = 1;
- if (type == kLeftRumble)
- m_leftRumble = value * 65535;
- else
- m_rightRumble = value * 65535;
- HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
-}
-
-/**
- * Set a single HID output value for the joystick.
- * @param outputNumber The index of the output to set (1-32)
- * @param value The value to set the output to
- */
-
-void Joystick::SetOutput(uint8_t outputNumber, bool value) {
- m_outputs =
- (m_outputs & ~(1 << (outputNumber - 1))) | (value << (outputNumber - 1));
-
- HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
-}
-
-/**
- * Set all HID output values for the joystick.
- * @param value The 32 bit output value (1 bit for each output)
- */
-void Joystick::SetOutputs(uint32_t value) {
- m_outputs = value;
- HALSetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
+ return (180/acos(-1))*GetDirectionRadians();
}