mirror of
https://github.com/team2059/Zaphod
synced 2024-12-18 20:12:28 -05:00
Moved the joystick to lib/controller and changed the existing code to work with it
This commit is contained in:
parent
4b104d4910
commit
aaeae5fd11
@ -2,7 +2,6 @@
|
|||||||
#define __HH_BASE_H__
|
#define __HH_BASE_H__
|
||||||
#include <WPILib.h>
|
#include <WPILib.h>
|
||||||
#include "HHRobot.h"
|
#include "HHRobot.h"
|
||||||
#include "Subsystems/Controller.h"
|
|
||||||
#include "Subsystems/Shooter.h"
|
#include "Subsystems/Shooter.h"
|
||||||
#include "Subsystems/Collector.h"
|
#include "Subsystems/Collector.h"
|
||||||
#include "Subsystems/Compressor.h"
|
#include "Subsystems/Compressor.h"
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
#include "HHBase.h"
|
#include "HHBase.h"
|
||||||
HHRobot::HHRobot():
|
HHRobot::HHRobot():
|
||||||
drive(new WCDrive(6,1,1,1,2,1,3,2,1,2,2,2,3)),
|
drive(new WCDrive(6,1,1,1,2,1,3,2,1,2,2,2,3)),
|
||||||
controlSystem(new JoystickController()),
|
driveStick(new Extreme3dPro(1)),
|
||||||
|
shootStick(new Extreme3dPro(2)),
|
||||||
shooter(new HHShooter()),
|
shooter(new HHShooter()),
|
||||||
collector(new HHCollector()),
|
collector(new HHCollector()),
|
||||||
compressorSystem(new HHCompressor()),
|
compressorSystem(new HHCompressor()),
|
||||||
@ -27,8 +28,8 @@ void HHRobot::Init(){
|
|||||||
compressorSystem->StartCompressor();
|
compressorSystem->StartCompressor();
|
||||||
}
|
}
|
||||||
bool HHRobot::CheckJoystickValues(){
|
bool HHRobot::CheckJoystickValues(){
|
||||||
float x=controlSystem->GetJoystickAxis(1,"x");
|
float x=driveStick->GetJoystickAxis("x");
|
||||||
float y=controlSystem->GetJoystickAxis(1,"y");
|
float y=driveStick->GetJoystickAxis("y");
|
||||||
if((-.1<x && x<.1) && (-.1<y && y<.1)) {
|
if((-.1<x && x<.1) && (-.1<y && y<.1)) {
|
||||||
dashboard->PutBoolValue("Joysticks Valid",true);
|
dashboard->PutBoolValue("Joysticks Valid",true);
|
||||||
return true;
|
return true;
|
||||||
@ -38,7 +39,7 @@ bool HHRobot::CheckJoystickValues(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HHRobot::UpdateDashboard(){
|
void HHRobot::UpdateDashboard(){
|
||||||
dashboard->PutFloatValue("Shooting Power",controlSystem->GetThrottle());
|
dashboard->PutFloatValue("Shooting Power",shootStick->GetThrottle());
|
||||||
}
|
}
|
||||||
void HHRobot::RunAuto(){
|
void HHRobot::RunAuto(){
|
||||||
timer->Reset();
|
timer->Reset();
|
||||||
@ -74,6 +75,8 @@ void HHRobot::Handler(){
|
|||||||
bool allowCompressing = true;
|
bool allowCompressing = true;
|
||||||
//Periodic tasks that should be run by every loop
|
//Periodic tasks that should be run by every loop
|
||||||
shooter->UpdateShooterPosition(targetAngle);
|
shooter->UpdateShooterPosition(targetAngle);
|
||||||
|
driveStick->handler();
|
||||||
|
shootStick->handler();
|
||||||
if(timer->Get()-lastTime>=0.5f){
|
if(timer->Get()-lastTime>=0.5f){
|
||||||
// Update compressor when current time-last time is more than .5 seconds
|
// Update compressor when current time-last time is more than .5 seconds
|
||||||
lastTime=timer->Get();
|
lastTime=timer->Get();
|
||||||
@ -81,39 +84,39 @@ void HHRobot::Handler(){
|
|||||||
}
|
}
|
||||||
collector->UpdateCollector(shooter->isShooting,shooter->GetAngle());
|
collector->UpdateCollector(shooter->isShooting,shooter->GetAngle());
|
||||||
//TODO Fix whatever the heck is wrong with this
|
//TODO Fix whatever the heck is wrong with this
|
||||||
drive->Update(6,controlSystem->GetJoystickAxis(1,"z")+controlSystem->GetJoystickAxis(1,"x"),controlSystem->GetJoystickAxis(1,"y"));
|
drive->Update(6,driveStick->GetJoystickAxis("z")+driveStick->GetJoystickAxis("x"),driveStick->GetJoystickAxis("y"));
|
||||||
UpdateDashboard();
|
UpdateDashboard();
|
||||||
//Shooting button
|
//Shooting button
|
||||||
if(controlSystem->GetJoystickButton(2,SHOOTER_FIRE)){
|
if(shootStick->ButtonValue[1]){
|
||||||
shooter->StartShootingSequence(controlSystem->GetThrottle());
|
shooter->StartShootingSequence(shootStick->GetThrottle());
|
||||||
}
|
}
|
||||||
//Collector button assignments
|
//Collector button assignments
|
||||||
if(controlSystem->GetJoystickButton(1,COLLECTOR_INTAKE)) {
|
if(driveStick->GetJoystickButton(COLLECTOR_INTAKE)) {
|
||||||
collector->CollectBall();
|
collector->CollectBall();
|
||||||
collectorTable->PutNumber("Current Collector Speed",1);
|
collectorTable->PutNumber("Current Collector Speed",1);
|
||||||
}else if(controlSystem->GetJoystickButton(1,COLLECTOR_OUTTAKE)) {
|
}else if(driveStick->GetJoystickButton(COLLECTOR_OUTTAKE)) {
|
||||||
collectorTable->PutNumber("Current Collector Speed",-1);
|
collectorTable->PutNumber("Current Collector Speed",-1);
|
||||||
collector->ReleaseBall();
|
collector->ReleaseBall();
|
||||||
}else{
|
}else{
|
||||||
collectorTable->PutNumber("Current Collector Speed",0);
|
collectorTable->PutNumber("Current Collector Speed",0);
|
||||||
collector->CollectorStop();
|
collector->CollectorStop();
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(1,COLLECTOR_EXTEND)){
|
if(driveStick->GetJoystickButton(COLLECTOR_EXTEND)){
|
||||||
compressorSystem->ExtendCollector();
|
compressorSystem->ExtendCollector();
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(1,COLLECTOR_RETRACT)){
|
if(driveStick->GetJoystickButton(COLLECTOR_RETRACT)){
|
||||||
compressorSystem->RetractCollector();
|
compressorSystem->RetractCollector();
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(2,SHOOTER_ANGLE_ONE)){
|
if(shootStick->GetJoystickButton(SHOOTER_ANGLE_ONE)){
|
||||||
targetAngle=100;
|
targetAngle=100;
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(2,SHOOTER_ANGLE_TWO)){
|
if(driveStick->GetJoystickButton(SHOOTER_ANGLE_TWO)){
|
||||||
targetAngle=120;
|
targetAngle=120;
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(2,SHOOTER_ANGLE_THREE)){
|
if(shootStick->GetJoystickButton(SHOOTER_ANGLE_THREE)){
|
||||||
targetAngle=90;
|
targetAngle=90;
|
||||||
}
|
}
|
||||||
if(controlSystem->GetJoystickButton(2,SHOOTER_ANGLE_FOUR)){
|
if(shootStick->GetJoystickButton(SHOOTER_ANGLE_FOUR)){
|
||||||
targetAngle=130;
|
targetAngle=130;
|
||||||
}
|
}
|
||||||
shooterTable->PutNumber("Target Shooter Angle",targetAngle);
|
shooterTable->PutNumber("Target Shooter Angle",targetAngle);
|
||||||
@ -132,7 +135,7 @@ void HHRobot::Handler(){
|
|||||||
// Shooting stuff
|
// Shooting stuff
|
||||||
shooterTable->PutNumber("Current Shooter Angle",shooter->GetAngle());
|
shooterTable->PutNumber("Current Shooter Angle",shooter->GetAngle());
|
||||||
shooterTable->PutNumber("Current Shooter State",shooter->e_ShooterState);
|
shooterTable->PutNumber("Current Shooter State",shooter->e_ShooterState);
|
||||||
shooterTable->PutNumber("Current Shooter Power",controlSystem->GetThrottle()*100);
|
shooterTable->PutNumber("Current Shooter Power",shootStick->GetThrottle()*100);
|
||||||
shooterTable->PutNumber("Current Shooter Power (raw)",controlSystem->GetThrottle() * 127.0f + 128);
|
shooterTable->PutNumber("Current Shooter Power (raw)",shootStick->GetThrottle() * 127.0f + 128);
|
||||||
}
|
}
|
||||||
// vim: ts=2:sw=2:et
|
// vim: ts=2:sw=2:et
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
#include <WPILib.h>
|
#include <WPILib.h>
|
||||||
#include "HHBase.h"
|
#include "HHBase.h"
|
||||||
#include "lib/drive/WCDrive.h"
|
#include "lib/drive/WCDrive.h"
|
||||||
|
#include "lib/controller/Controller.h"
|
||||||
#include "Definitions.h"
|
#include "Definitions.h"
|
||||||
class JoystickController;
|
|
||||||
class HHShooter;
|
class HHShooter;
|
||||||
class HHCollector;
|
class HHCollector;
|
||||||
class HHCompressor;
|
class HHCompressor;
|
||||||
@ -13,9 +13,8 @@ class HHRobot;
|
|||||||
class HHSonar;
|
class HHSonar;
|
||||||
class HHRobot{
|
class HHRobot{
|
||||||
private:
|
private:
|
||||||
Joystick *rightStick, *leftStick;
|
|
||||||
WCDrive *drive;
|
WCDrive *drive;
|
||||||
JoystickController *controlSystem;
|
Extreme3dPro *driveStick, *shootStick;
|
||||||
NetworkTable *driveTable, *shooterTable, *collectorTable;
|
NetworkTable *driveTable, *shooterTable, *collectorTable;
|
||||||
HHShooter *shooter;
|
HHShooter *shooter;
|
||||||
HHCollector *collector;
|
HHCollector *collector;
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
#include "Controller.h"
|
|
||||||
JoystickController::JoystickController(){
|
|
||||||
driveJoystick=new Joystick(JOYSTICK_RIGHT);
|
|
||||||
shootJoystick=new Joystick(JOYSTICK_LEFT);
|
|
||||||
}
|
|
||||||
float JoystickController::GetThrottle(){
|
|
||||||
return (-GetRawJoystickAxis(2,4)+1)/2;
|
|
||||||
}
|
|
||||||
int JoystickController::GetJoystickButton(int joystick, int button){
|
|
||||||
switch (joystick){
|
|
||||||
case 1:
|
|
||||||
return driveJoystick->GetRawButton(button);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return shootJoystick->GetRawButton(button);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("Button from joystick %d does not exist!\n", joystick);
|
|
||||||
return -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float JoystickController::GetRawJoystickAxis(int joystick, int axis){
|
|
||||||
switch (joystick){
|
|
||||||
case 1:
|
|
||||||
return driveJoystick->GetRawAxis(axis);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return shootJoystick->GetRawAxis(axis);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("Axis from joystick %d does not exist!\n", joystick);
|
|
||||||
return 999;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float JoystickController::GetJoystickAxis(int joystick, std::string axis){
|
|
||||||
if (joystick == 1) {
|
|
||||||
if (axis == "x"){
|
|
||||||
return driveJoystick->GetX();
|
|
||||||
}else if (axis == "y"){
|
|
||||||
return driveJoystick->GetY();
|
|
||||||
}else if (axis == "z"){
|
|
||||||
return driveJoystick->GetZ();
|
|
||||||
}else if(axis == "throttle"){
|
|
||||||
return driveJoystick->GetRawAxis(4);
|
|
||||||
}
|
|
||||||
}else if(joystick == 2){
|
|
||||||
if (axis == "x"){
|
|
||||||
return shootJoystick->GetX();
|
|
||||||
}else if (axis == "y"){
|
|
||||||
return shootJoystick->GetY();
|
|
||||||
}else if (axis == "z"){
|
|
||||||
return shootJoystick->GetZ();
|
|
||||||
}else if(axis == "throttle"){
|
|
||||||
return shootJoystick->GetRawAxis(4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// vim: ts=2:sw=2:et
|
|
@ -1,14 +0,0 @@
|
|||||||
#include <WPILib.h>
|
|
||||||
#include "../Definitions.h"
|
|
||||||
class JoystickController
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Joystick *driveJoystick, *shootJoystick;
|
|
||||||
public:
|
|
||||||
JoystickController();
|
|
||||||
float GetThrottle();
|
|
||||||
int GetJoystickButton(int,int);
|
|
||||||
float GetRawJoystickAxis(int,int);
|
|
||||||
float GetJoystickAxis(int, std::string axis);
|
|
||||||
};
|
|
||||||
// vim: ts=2:sw=2:et
|
|
19
src/lib/controller/Controller.h
Normal file
19
src/lib/controller/Controller.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <WPILib.h>
|
||||||
|
#include "../Definitions.h"
|
||||||
|
// Logitech Extreme 3D Pro joysticks
|
||||||
|
class Extreme3dPro
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Joystick *stickofjoy;
|
||||||
|
public:
|
||||||
|
//Array to hold joystick button values
|
||||||
|
int ButtonValue[11];
|
||||||
|
//Call periodically to update joystick values
|
||||||
|
void handler();
|
||||||
|
Extreme3dPro(uint8_t);
|
||||||
|
float GetThrottle();
|
||||||
|
int GetJoystickButton(uint8_t);
|
||||||
|
float GetRawJoystickAxis(uint8_t);
|
||||||
|
float GetJoystickAxis(std::string axis);
|
||||||
|
};
|
||||||
|
// vim: ts=2:sw=2:et
|
32
src/lib/controller/Extreme3dPro.cpp
Normal file
32
src/lib/controller/Extreme3dPro.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "Controller.h"
|
||||||
|
Extreme3dPro::Extreme3dPro(uint8_t port){
|
||||||
|
stickofjoy = new Joystick(port);
|
||||||
|
}
|
||||||
|
float Extreme3dPro::GetThrottle(){
|
||||||
|
return (-GetRawJoystickAxis(4)+1)/2;
|
||||||
|
}
|
||||||
|
int Extreme3dPro::GetJoystickButton(uint8_t button){
|
||||||
|
return stickofjoy->GetRawButton(button);
|
||||||
|
}
|
||||||
|
float Extreme3dPro::GetRawJoystickAxis(uint8_t axis){
|
||||||
|
return stickofjoy->GetRawAxis(axis);
|
||||||
|
}
|
||||||
|
float Extreme3dPro::GetJoystickAxis(std::string axis){
|
||||||
|
if (axis == "x"){
|
||||||
|
return stickofjoy->GetX();
|
||||||
|
}else if (axis == "y"){
|
||||||
|
return stickofjoy->GetY();
|
||||||
|
}else if (axis == "z"){
|
||||||
|
return stickofjoy->GetZ();
|
||||||
|
}else if(axis == "throttle"){
|
||||||
|
return stickofjoy->GetRawAxis(4);
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Extreme3dPro::handler(){
|
||||||
|
for(int i=0;i<=11;i++){
|
||||||
|
ButtonValue[i] = stickofjoy->GetRawButton(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// vim: ts=2:sw=2:et
|
Loading…
Reference in New Issue
Block a user