2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/RobotDrive.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-09-05 13:55:31 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/HAL.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/GenericHID.h"
|
|
|
|
|
#include "frc/Joystick.h"
|
|
|
|
|
#include "frc/Talon.h"
|
|
|
|
|
#include "frc/Utility.h"
|
|
|
|
|
#include "frc/WPIErrors.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2017-07-08 14:17:21 -07:00
|
|
|
static std::shared_ptr<SpeedController> make_shared_nodelete(
|
|
|
|
|
SpeedController* ptr) {
|
2015-07-29 16:48:04 -04:00
|
|
|
return std::shared_ptr<SpeedController>(ptr, NullDeleter<SpeedController>());
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
RobotDrive::RobotDrive(int leftMotorChannel, int rightMotorChannel) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
2015-07-29 16:48:04 -04:00
|
|
|
m_rearLeftMotor = std::make_shared<Talon>(leftMotorChannel);
|
|
|
|
|
m_rearRightMotor = std::make_shared<Talon>(rightMotorChannel);
|
2015-06-25 15:07:55 -04:00
|
|
|
SetLeftRightMotorOutputs(0.0, 0.0);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
RobotDrive::RobotDrive(int frontLeftMotor, int rearLeftMotor,
|
|
|
|
|
int frontRightMotor, int rearRightMotor) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
2015-07-29 16:48:04 -04:00
|
|
|
m_rearLeftMotor = std::make_shared<Talon>(rearLeftMotor);
|
|
|
|
|
m_rearRightMotor = std::make_shared<Talon>(rearRightMotor);
|
|
|
|
|
m_frontLeftMotor = std::make_shared<Talon>(frontLeftMotor);
|
|
|
|
|
m_frontRightMotor = std::make_shared<Talon>(frontRightMotor);
|
2015-06-25 15:07:55 -04:00
|
|
|
SetLeftRightMotorOutputs(0.0, 0.0);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
RobotDrive::RobotDrive(SpeedController* leftMotor,
|
|
|
|
|
SpeedController* rightMotor) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
2015-06-23 04:49:51 -07:00
|
|
|
if (leftMotor == nullptr || rightMotor == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setWPIError(NullParameter);
|
2015-06-23 04:49:51 -07:00
|
|
|
m_rearLeftMotor = m_rearRightMotor = nullptr;
|
2015-06-25 15:07:55 -04:00
|
|
|
return;
|
|
|
|
|
}
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_rearLeftMotor = make_shared_nodelete(leftMotor);
|
|
|
|
|
m_rearRightMotor = make_shared_nodelete(rightMotor);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
RobotDrive::RobotDrive(SpeedController& leftMotor,
|
|
|
|
|
SpeedController& rightMotor) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_rearLeftMotor = make_shared_nodelete(&leftMotor);
|
|
|
|
|
m_rearRightMotor = make_shared_nodelete(&rightMotor);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
RobotDrive::RobotDrive(std::shared_ptr<SpeedController> leftMotor,
|
|
|
|
|
std::shared_ptr<SpeedController> rightMotor) {
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
InitRobotDrive();
|
|
|
|
|
if (leftMotor == nullptr || rightMotor == nullptr) {
|
|
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
m_rearLeftMotor = m_rearRightMotor = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_rearLeftMotor = leftMotor;
|
|
|
|
|
m_rearRightMotor = rightMotor;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
RobotDrive::RobotDrive(SpeedController* frontLeftMotor,
|
|
|
|
|
SpeedController* rearLeftMotor,
|
|
|
|
|
SpeedController* frontRightMotor,
|
|
|
|
|
SpeedController* rearRightMotor) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
2015-06-23 04:49:51 -07:00
|
|
|
if (frontLeftMotor == nullptr || rearLeftMotor == nullptr ||
|
|
|
|
|
frontRightMotor == nullptr || rearRightMotor == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_frontLeftMotor = make_shared_nodelete(frontLeftMotor);
|
|
|
|
|
m_rearLeftMotor = make_shared_nodelete(rearLeftMotor);
|
|
|
|
|
m_frontRightMotor = make_shared_nodelete(frontRightMotor);
|
|
|
|
|
m_rearRightMotor = make_shared_nodelete(rearRightMotor);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
RobotDrive::RobotDrive(SpeedController& frontLeftMotor,
|
|
|
|
|
SpeedController& rearLeftMotor,
|
|
|
|
|
SpeedController& frontRightMotor,
|
|
|
|
|
SpeedController& rearRightMotor) {
|
2015-06-25 15:07:55 -04:00
|
|
|
InitRobotDrive();
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_frontLeftMotor = make_shared_nodelete(&frontLeftMotor);
|
|
|
|
|
m_rearLeftMotor = make_shared_nodelete(&rearLeftMotor);
|
|
|
|
|
m_frontRightMotor = make_shared_nodelete(&frontRightMotor);
|
|
|
|
|
m_rearRightMotor = make_shared_nodelete(&rearRightMotor);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
RobotDrive::RobotDrive(std::shared_ptr<SpeedController> frontLeftMotor,
|
|
|
|
|
std::shared_ptr<SpeedController> rearLeftMotor,
|
|
|
|
|
std::shared_ptr<SpeedController> frontRightMotor,
|
|
|
|
|
std::shared_ptr<SpeedController> rearRightMotor) {
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
InitRobotDrive();
|
|
|
|
|
if (frontLeftMotor == nullptr || rearLeftMotor == nullptr ||
|
|
|
|
|
frontRightMotor == nullptr || rearRightMotor == nullptr) {
|
|
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
return;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_frontLeftMotor = frontLeftMotor;
|
|
|
|
|
m_rearLeftMotor = rearLeftMotor;
|
|
|
|
|
m_frontRightMotor = frontRightMotor;
|
|
|
|
|
m_rearRightMotor = rearRightMotor;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::Drive(double outputMagnitude, double curve) {
|
|
|
|
|
double leftOutput, rightOutput;
|
2015-06-25 15:07:55 -04:00
|
|
|
static bool reported = false;
|
|
|
|
|
if (!reported) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(),
|
|
|
|
|
HALUsageReporting::kRobotDrive_ArcadeRatioCurve);
|
2015-06-25 15:07:55 -04:00
|
|
|
reported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (curve < 0) {
|
2016-11-20 07:25:03 -08:00
|
|
|
double value = std::log(-curve);
|
|
|
|
|
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (ratio == 0) ratio = .0000000001;
|
|
|
|
|
leftOutput = outputMagnitude / ratio;
|
|
|
|
|
rightOutput = outputMagnitude;
|
|
|
|
|
} else if (curve > 0) {
|
2016-11-20 07:25:03 -08:00
|
|
|
double value = std::log(curve);
|
|
|
|
|
double ratio = (value - m_sensitivity) / (value + m_sensitivity);
|
2015-06-25 15:07:55 -04:00
|
|
|
if (ratio == 0) ratio = .0000000001;
|
|
|
|
|
leftOutput = outputMagnitude;
|
|
|
|
|
rightOutput = outputMagnitude / ratio;
|
|
|
|
|
} else {
|
|
|
|
|
leftOutput = outputMagnitude;
|
|
|
|
|
rightOutput = outputMagnitude;
|
|
|
|
|
}
|
|
|
|
|
SetLeftRightMotorOutputs(leftOutput, rightOutput);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void RobotDrive::TankDrive(GenericHID* leftStick, GenericHID* rightStick,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (leftStick == nullptr || rightStick == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TankDrive(leftStick->GetY(), rightStick->GetY(), squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void RobotDrive::TankDrive(GenericHID& leftStick, GenericHID& rightStick,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
|
|
|
|
TankDrive(leftStick.GetY(), rightStick.GetY(), squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
void RobotDrive::TankDrive(GenericHID* leftStick, int leftAxis,
|
|
|
|
|
GenericHID* rightStick, int rightAxis,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (leftStick == nullptr || rightStick == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setWPIError(NullParameter);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TankDrive(leftStick->GetRawAxis(leftAxis), rightStick->GetRawAxis(rightAxis),
|
|
|
|
|
squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
void RobotDrive::TankDrive(GenericHID& leftStick, int leftAxis,
|
|
|
|
|
GenericHID& rightStick, int rightAxis,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
|
|
|
|
TankDrive(leftStick.GetRawAxis(leftAxis), rightStick.GetRawAxis(rightAxis),
|
|
|
|
|
squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::TankDrive(double leftValue, double rightValue,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
|
|
|
|
static bool reported = false;
|
|
|
|
|
if (!reported) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(),
|
|
|
|
|
HALUsageReporting::kRobotDrive_Tank);
|
2015-06-25 15:07:55 -04:00
|
|
|
reported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leftValue = Limit(leftValue);
|
|
|
|
|
rightValue = Limit(rightValue);
|
2017-05-07 09:40:48 -07:00
|
|
|
|
|
|
|
|
// square the inputs (while preserving the sign) to increase fine control
|
|
|
|
|
// while permitting full power
|
2015-06-25 15:07:55 -04:00
|
|
|
if (squaredInputs) {
|
2017-05-07 09:40:48 -07:00
|
|
|
leftValue = std::copysign(leftValue * leftValue, leftValue);
|
|
|
|
|
rightValue = std::copysign(rightValue * rightValue, rightValue);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetLeftRightMotorOutputs(leftValue, rightValue);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void RobotDrive::ArcadeDrive(GenericHID* stick, bool squaredInputs) {
|
2015-06-25 15:07:55 -04:00
|
|
|
// simply call the full-featured ArcadeDrive with the appropriate values
|
|
|
|
|
ArcadeDrive(stick->GetY(), stick->GetX(), squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
void RobotDrive::ArcadeDrive(GenericHID& stick, bool squaredInputs) {
|
2015-06-25 15:07:55 -04:00
|
|
|
// simply call the full-featured ArcadeDrive with the appropriate values
|
|
|
|
|
ArcadeDrive(stick.GetY(), stick.GetX(), squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
void RobotDrive::ArcadeDrive(GenericHID* moveStick, int moveAxis,
|
|
|
|
|
GenericHID* rotateStick, int rotateAxis,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
2016-11-20 07:25:03 -08:00
|
|
|
double moveValue = moveStick->GetRawAxis(moveAxis);
|
|
|
|
|
double rotateValue = rotateStick->GetRawAxis(rotateAxis);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
ArcadeDrive(moveValue, rotateValue, squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
void RobotDrive::ArcadeDrive(GenericHID& moveStick, int moveAxis,
|
|
|
|
|
GenericHID& rotateStick, int rotateAxis,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
2016-11-20 07:25:03 -08:00
|
|
|
double moveValue = moveStick.GetRawAxis(moveAxis);
|
|
|
|
|
double rotateValue = rotateStick.GetRawAxis(rotateAxis);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
ArcadeDrive(moveValue, rotateValue, squaredInputs);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::ArcadeDrive(double moveValue, double rotateValue,
|
2015-06-25 15:07:55 -04:00
|
|
|
bool squaredInputs) {
|
|
|
|
|
static bool reported = false;
|
|
|
|
|
if (!reported) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(),
|
|
|
|
|
HALUsageReporting::kRobotDrive_ArcadeStandard);
|
2015-06-25 15:07:55 -04:00
|
|
|
reported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// local variables to hold the computed PWM values for the motors
|
2016-11-20 07:25:03 -08:00
|
|
|
double leftMotorOutput;
|
|
|
|
|
double rightMotorOutput;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
moveValue = Limit(moveValue);
|
|
|
|
|
rotateValue = Limit(rotateValue);
|
|
|
|
|
|
2017-05-07 09:40:48 -07:00
|
|
|
// square the inputs (while preserving the sign) to increase fine control
|
|
|
|
|
// while permitting full power
|
2015-06-25 15:07:55 -04:00
|
|
|
if (squaredInputs) {
|
2017-05-07 09:40:48 -07:00
|
|
|
moveValue = std::copysign(moveValue * moveValue, moveValue);
|
|
|
|
|
rotateValue = std::copysign(rotateValue * rotateValue, rotateValue);
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (moveValue > 0.0) {
|
|
|
|
|
if (rotateValue > 0.0) {
|
|
|
|
|
leftMotorOutput = moveValue - rotateValue;
|
|
|
|
|
rightMotorOutput = std::max(moveValue, rotateValue);
|
|
|
|
|
} else {
|
|
|
|
|
leftMotorOutput = std::max(moveValue, -rotateValue);
|
|
|
|
|
rightMotorOutput = moveValue + rotateValue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (rotateValue > 0.0) {
|
|
|
|
|
leftMotorOutput = -std::max(-moveValue, rotateValue);
|
|
|
|
|
rightMotorOutput = moveValue + rotateValue;
|
|
|
|
|
} else {
|
|
|
|
|
leftMotorOutput = moveValue - rotateValue;
|
|
|
|
|
rightMotorOutput = -std::max(-moveValue, -rotateValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SetLeftRightMotorOutputs(leftMotorOutput, rightMotorOutput);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::MecanumDrive_Cartesian(double x, double y, double rotation,
|
|
|
|
|
double gyroAngle) {
|
2015-06-25 15:07:55 -04:00
|
|
|
static bool reported = false;
|
|
|
|
|
if (!reported) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(),
|
|
|
|
|
HALUsageReporting::kRobotDrive_MecanumCartesian);
|
2015-06-25 15:07:55 -04:00
|
|
|
reported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double xIn = x;
|
|
|
|
|
double yIn = y;
|
|
|
|
|
// Negate y for the joystick.
|
|
|
|
|
yIn = -yIn;
|
|
|
|
|
// Compenstate for gyro angle.
|
|
|
|
|
RotateVector(xIn, yIn, gyroAngle);
|
|
|
|
|
|
|
|
|
|
double wheelSpeeds[kMaxNumberOfMotors];
|
|
|
|
|
wheelSpeeds[kFrontLeftMotor] = xIn + yIn + rotation;
|
|
|
|
|
wheelSpeeds[kFrontRightMotor] = -xIn + yIn - rotation;
|
|
|
|
|
wheelSpeeds[kRearLeftMotor] = -xIn + yIn + rotation;
|
|
|
|
|
wheelSpeeds[kRearRightMotor] = xIn + yIn - rotation;
|
|
|
|
|
|
|
|
|
|
Normalize(wheelSpeeds);
|
|
|
|
|
|
2016-05-23 20:42:58 -07:00
|
|
|
m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_maxOutput);
|
|
|
|
|
m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_maxOutput);
|
|
|
|
|
m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_maxOutput);
|
|
|
|
|
m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_maxOutput);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
Feed();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::MecanumDrive_Polar(double magnitude, double direction,
|
|
|
|
|
double rotation) {
|
2015-06-25 15:07:55 -04:00
|
|
|
static bool reported = false;
|
|
|
|
|
if (!reported) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(),
|
|
|
|
|
HALUsageReporting::kRobotDrive_MecanumPolar);
|
2015-06-25 15:07:55 -04:00
|
|
|
reported = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normalized for full power along the Cartesian axes.
|
2016-09-05 13:55:31 -07:00
|
|
|
magnitude = Limit(magnitude) * std::sqrt(2.0);
|
2015-06-25 15:07:55 -04:00
|
|
|
// The rollers are at 45 degree angles.
|
|
|
|
|
double dirInRad = (direction + 45.0) * 3.14159 / 180.0;
|
2016-09-05 13:55:31 -07:00
|
|
|
double cosD = std::cos(dirInRad);
|
|
|
|
|
double sinD = std::sin(dirInRad);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
double wheelSpeeds[kMaxNumberOfMotors];
|
|
|
|
|
wheelSpeeds[kFrontLeftMotor] = sinD * magnitude + rotation;
|
|
|
|
|
wheelSpeeds[kFrontRightMotor] = cosD * magnitude - rotation;
|
|
|
|
|
wheelSpeeds[kRearLeftMotor] = cosD * magnitude + rotation;
|
|
|
|
|
wheelSpeeds[kRearRightMotor] = sinD * magnitude - rotation;
|
|
|
|
|
|
|
|
|
|
Normalize(wheelSpeeds);
|
|
|
|
|
|
2016-05-23 20:42:58 -07:00
|
|
|
m_frontLeftMotor->Set(wheelSpeeds[kFrontLeftMotor] * m_maxOutput);
|
|
|
|
|
m_frontRightMotor->Set(wheelSpeeds[kFrontRightMotor] * m_maxOutput);
|
|
|
|
|
m_rearLeftMotor->Set(wheelSpeeds[kRearLeftMotor] * m_maxOutput);
|
|
|
|
|
m_rearRightMotor->Set(wheelSpeeds[kRearRightMotor] * m_maxOutput);
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
Feed();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::HolonomicDrive(double magnitude, double direction,
|
|
|
|
|
double rotation) {
|
2015-06-25 15:07:55 -04:00
|
|
|
MecanumDrive_Polar(magnitude, direction, rotation);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::SetLeftRightMotorOutputs(double leftOutput,
|
|
|
|
|
double rightOutput) {
|
2015-06-23 04:49:51 -07:00
|
|
|
wpi_assert(m_rearLeftMotor != nullptr && m_rearRightMotor != nullptr);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-23 04:49:51 -07:00
|
|
|
if (m_frontLeftMotor != nullptr)
|
2016-05-23 20:42:58 -07:00
|
|
|
m_frontLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
|
|
|
|
m_rearLeftMotor->Set(Limit(leftOutput) * m_maxOutput);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-23 04:49:51 -07:00
|
|
|
if (m_frontRightMotor != nullptr)
|
2016-05-23 20:42:58 -07:00
|
|
|
m_frontRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
|
|
|
|
m_rearRightMotor->Set(-Limit(rightOutput) * m_maxOutput);
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
Feed();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void RobotDrive::SetInvertedMotor(MotorType motor, bool isInverted) {
|
|
|
|
|
if (motor < 0 || motor > 3) {
|
|
|
|
|
wpi_setWPIError(InvalidMotorIndex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (motor) {
|
|
|
|
|
case kFrontLeftMotor:
|
|
|
|
|
m_frontLeftMotor->SetInverted(isInverted);
|
|
|
|
|
break;
|
|
|
|
|
case kFrontRightMotor:
|
|
|
|
|
m_frontRightMotor->SetInverted(isInverted);
|
|
|
|
|
break;
|
|
|
|
|
case kRearLeftMotor:
|
|
|
|
|
m_rearLeftMotor->SetInverted(isInverted);
|
|
|
|
|
break;
|
|
|
|
|
case kRearRightMotor:
|
|
|
|
|
m_rearRightMotor->SetInverted(isInverted);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
void RobotDrive::SetSensitivity(double sensitivity) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_sensitivity = sensitivity;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void RobotDrive::SetMaxOutput(double maxOutput) { m_maxOutput = maxOutput; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
void RobotDrive::GetDescription(wpi::raw_ostream& desc) const {
|
|
|
|
|
desc << "RobotDrive";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
void RobotDrive::StopMotor() {
|
|
|
|
|
if (m_frontLeftMotor != nullptr) m_frontLeftMotor->StopMotor();
|
|
|
|
|
if (m_frontRightMotor != nullptr) m_frontRightMotor->StopMotor();
|
|
|
|
|
if (m_rearLeftMotor != nullptr) m_rearLeftMotor->StopMotor();
|
|
|
|
|
if (m_rearRightMotor != nullptr) m_rearRightMotor->StopMotor();
|
2018-11-22 21:15:26 -08:00
|
|
|
Feed();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2018-11-22 21:15:26 -08:00
|
|
|
void RobotDrive::InitRobotDrive() { SetSafetyEnabled(true); }
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
double RobotDrive::Limit(double number) {
|
|
|
|
|
if (number > 1.0) {
|
|
|
|
|
return 1.0;
|
|
|
|
|
}
|
|
|
|
|
if (number < -1.0) {
|
|
|
|
|
return -1.0;
|
|
|
|
|
}
|
|
|
|
|
return number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RobotDrive::Normalize(double* wheelSpeeds) {
|
|
|
|
|
double maxMagnitude = std::fabs(wheelSpeeds[0]);
|
|
|
|
|
for (int i = 1; i < kMaxNumberOfMotors; i++) {
|
|
|
|
|
double temp = std::fabs(wheelSpeeds[i]);
|
|
|
|
|
if (maxMagnitude < temp) maxMagnitude = temp;
|
|
|
|
|
}
|
|
|
|
|
if (maxMagnitude > 1.0) {
|
|
|
|
|
for (int i = 0; i < kMaxNumberOfMotors; i++) {
|
|
|
|
|
wheelSpeeds[i] = wheelSpeeds[i] / maxMagnitude;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RobotDrive::RotateVector(double& x, double& y, double angle) {
|
|
|
|
|
double cosA = std::cos(angle * (3.14159 / 180.0));
|
|
|
|
|
double sinA = std::sin(angle * (3.14159 / 180.0));
|
|
|
|
|
double xOut = x * cosA - y * sinA;
|
|
|
|
|
double yOut = x * sinA + y * cosA;
|
|
|
|
|
x = xOut;
|
|
|
|
|
y = yOut;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|