Files
allwpilib/wpilibc/wpilibC++Devices/include/RobotDrive.h
Patrick 0122086d23 Added tests for motor inversions.
This commit squashes all of Patrick's eleven commits into one
so that things are a bit more sane. The original commit messages
and change ids (for gerrit) can be found below.

Testing Motor Inversion Feature (Java tests only so far)

Change-Id: I44cd9b5a3fe066e1071316831dde14bff5ec3bd9

Test 2 of java testing for Motor Inverting

Change-Id: I96cc0534bb1d28a70d10c582f0b40ea3a2d83cab

Added another test to try to track down issue with InvertingMotor jaguar and Talon

Change-Id: I9b5292315c93ec0d568d53a6bcdac5b998a6d857

More Testing on the Inverting motors with jaguars and talons.

Change-Id: I896210a54903e3c0af68e8c41360c165cf9c3122

Added C++ integration Tests for the motor inversion.

Change-Id: I81af5d4aab78d755340d99608b838046bf7ddda1

C++ tests for Motor Inversion now without crashing

Change-Id: Ifdecdbfc1aeb18aafb2b4c63709b27636074a274

More testing of inverted motors (now with c++ tests)
Talon seems not to be working on test rig
Also added a CANJaguartest file in java since was missing
Currently porting the CANJaguar tests from c++ to java

Change-Id: Ib578d6ee1256ac31ddf20603aa6f24adde08065b

Another attempt at adding java tests for can jaguar inversion.

Change-Id: I971a886a4e555ada5bd15a814094da2a1eb5c8e1

Minor changes and attempt to rerun tests after yesterday's jenkins crash.

Change-Id: I7ed0904d4243499c3246e9c39e5493d0d9c962c5

All motor inversion tests should be working now. Talon on the test rig has been fixed.

Change-Id: I20bd6d7486b758ce1ce47ac799150475b3152b6f

Updated Inversion tests again. Should work this time. (worked on the test rig prior)

Change-Id: Ifdf222d5e5733fe802f29e7d939b72e84972e8da

Added tests for motor inversions.

This commit squashes all of Patrick's eleven commits into one
so that things are a bit more sane. The original commit messages
and change ids (for gerrit) can be found below.

Testing Motor Inversion Feature (Java tests only so far)

Change-Id: I44cd9b5a3fe066e1071316831dde14bff5ec3bd9

Test 2 of java testing for Motor Inverting

Change-Id: I96cc0534bb1d28a70d10c582f0b40ea3a2d83cab

Added another test to try to track down issue with InvertingMotor jaguar and Talon

Change-Id: I9b5292315c93ec0d568d53a6bcdac5b998a6d857

More Testing on the Inverting motors with jaguars and talons.

Change-Id: I896210a54903e3c0af68e8c41360c165cf9c3122

Added C++ integration Tests for the motor inversion.

Change-Id: I81af5d4aab78d755340d99608b838046bf7ddda1

C++ tests for Motor Inversion now without crashing

Change-Id: Ifdecdbfc1aeb18aafb2b4c63709b27636074a274

More testing of inverted motors (now with c++ tests)
Talon seems not to be working on test rig
Also added a CANJaguartest file in java since was missing
Currently porting the CANJaguar tests from c++ to java

Change-Id: Ib578d6ee1256ac31ddf20603aa6f24adde08065b

Another attempt at adding java tests for can jaguar inversion.

Change-Id: I971a886a4e555ada5bd15a814094da2a1eb5c8e1

Minor changes and attempt to rerun tests after yesterday's jenkins crash.

Change-Id: I7ed0904d4243499c3246e9c39e5493d0d9c962c5

All motor inversion tests should be working now. Talon on the test rig has been fixed.

Change-Id: I20bd6d7486b758ce1ce47ac799150475b3152b6f

Updated Inversion tests again. Should work this time. (worked on the test rig prior)

Change-Id: Ifdf222d5e5733fe802f29e7d939b72e84972e8da
2015-06-25 14:55:06 -04:00

113 lines
4.5 KiB
C++

/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "ErrorBase.h"
#include <stdlib.h>
#include "HAL/HAL.hpp"
#include "MotorSafety.h"
#include "MotorSafetyHelper.h"
class SpeedController;
class GenericHID;
/**
* Utility class for handling Robot drive based on a definition of the motor configuration.
* The robot drive class handles basic driving for a robot. Currently, 2 and 4 motor tank and
* mecanum drive trains are supported. In the future other drive types like swerve might be
* implemented. Motor channel numbers are passed supplied on creation of the class. Those
* are used for either the Drive function (intended for hand created drive code, such as
* autonomous) or with the Tank/Arcade functions intended to be used for Operator Control
* driving.
*/
class RobotDrive : public MotorSafety, public ErrorBase
{
public:
enum MotorType
{
kFrontLeftMotor = 0,
kFrontRightMotor = 1,
kRearLeftMotor = 2,
kRearRightMotor = 3
};
RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel);
RobotDrive(uint32_t frontLeftMotorChannel, uint32_t rearLeftMotorChannel,
uint32_t frontRightMotorChannel, uint32_t rearRightMotorChannel);
RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor);
RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor);
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
SpeedController *frontRightMotor, SpeedController *rearRightMotor);
RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
SpeedController &frontRightMotor, SpeedController &rearRightMotor);
virtual ~RobotDrive();
void Drive(float outputMagnitude, float curve);
void TankDrive(GenericHID *leftStick, GenericHID *rightStick, bool squaredInputs = true);
void TankDrive(GenericHID &leftStick, GenericHID &rightStick, bool squaredInputs = true);
void TankDrive(GenericHID *leftStick, uint32_t leftAxis, GenericHID *rightStick,
uint32_t rightAxis, bool squaredInputs = true);
void TankDrive(GenericHID &leftStick, uint32_t leftAxis, GenericHID &rightStick,
uint32_t rightAxis, bool squaredInputs = true);
void TankDrive(float leftValue, float rightValue, bool squaredInputs = true);
void ArcadeDrive(GenericHID *stick, bool squaredInputs = true);
void ArcadeDrive(GenericHID &stick, bool squaredInputs = true);
void ArcadeDrive(GenericHID *moveStick, uint32_t moveChannel, GenericHID *rotateStick,
uint32_t rotateChannel, bool squaredInputs = true);
void ArcadeDrive(GenericHID &moveStick, uint32_t moveChannel, GenericHID &rotateStick,
uint32_t rotateChannel, bool squaredInputs = true);
void ArcadeDrive(float moveValue, float rotateValue, bool squaredInputs = true);
void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle = 0.0);
void MecanumDrive_Polar(float magnitude, float direction, float rotation);
void HolonomicDrive(float magnitude, float direction, float rotation);
virtual void SetLeftRightMotorOutputs(float leftOutput, float rightOutput);
void SetInvertedMotor(MotorType motor, bool isInverted);
void SetSensitivity(float sensitivity);
void SetMaxOutput(double maxOutput);
void SetCANJaguarSyncGroup(uint8_t syncGroup);
void SetExpiration(float timeout) override;
float GetExpiration() const override;
bool IsAlive() const override;
void StopMotor() override;
bool IsSafetyEnabled() const override;
void SetSafetyEnabled(bool enabled) override;
void GetDescription(char *desc) const override;
protected:
void InitRobotDrive();
float Limit(float num);
void Normalize(double *wheelSpeeds);
void RotateVector(double &x, double &y, double angle);
static const int32_t kMaxNumberOfMotors = 4;
float m_sensitivity;
double m_maxOutput;
bool m_deleteSpeedControllers;
SpeedController *m_frontLeftMotor;
SpeedController *m_frontRightMotor;
SpeedController *m_rearLeftMotor;
SpeedController *m_rearRightMotor;
MotorSafetyHelper *m_safetyHelper;
uint8_t m_syncGroup;
private:
int32_t GetNumMotors()
{
int motors = 0;
if (m_frontLeftMotor)
motors++;
if (m_frontRightMotor)
motors++;
if (m_rearLeftMotor)
motors++;
if (m_rearRightMotor)
motors++;
return motors;
}
DISALLOW_COPY_AND_ASSIGN(RobotDrive);
};