#include "WPILib.h" #include "Shooter.h" #include #ifndef BUTTON_LAYOUT #define BUTTON_LAYOUT #define TRIGGER 1 // Trigger button number #define THUMB 2 // Thumb button number #define RAMP_RAISE 3 // Button 3 for Raising Ramp #define RAMP_LOWER 4 // Button 4 to lower ramp. #endif // BUTTON_LAYOUT class Robot: public IterativeRobot { TalonSRX left_drive, right_drive; CANTalon shooter1, shooter2, ramp; RobotDrive drive; Shooter shooter; Joystick driver_stick, operator_stick; Counter ramp_height; public: Robot(): left_drive(0), // Left DriveTrain Talons plug into PWM channel 1 with a Y-spliter right_drive(1), // Right DriveTrain Talons plug // left wheel 2 shooter1(10), // shooter drive 1 shooter2(11), // shooter drive 2 ramp(12), drive(&left_drive, &right_drive), ramp_height(), shooter( // initialize Shooter object. &shooter1, &shooter2, &ramp, &ramp_height), driver_stick(0), // right stick (operator) operator_stick(1) // left stick (driver) { } private: // instance variables bool pickupRunning; // don't want to spam the Talon with set messages. Toggle the pickup when a button is pressed or released. bool inverting; float theta; float old_theta; LiveWindow *lw = LiveWindow::GetInstance(); SendableChooser *chooser; const std::string autoNameDefault = "Default"; const std::string autoNameCustom = "My Auto"; std::string autoSelected; void RobotInit() { chooser = new SendableChooser(); chooser->AddDefault(autoNameDefault, (void*)&autoNameDefault); chooser->AddObject(autoNameCustom, (void*)&autoNameCustom); SmartDashboard::PutData("Auto Modes", chooser); ramp_height.SetUpSource(1); ramp.Enable(); shooter1.Enable(); shooter2.Enable(); left_drive.SetInverted(true); right_drive.SetInverted(true); inverting = false; } /** * This autonomous (along with the chooser code above) shows how to select between different autonomous modes * using the dashboard. The sendable chooser code works with the Java SmartDashboard. If you prefer the LabVIEW * Dashboard, remove all of the chooser code and uncomment the GetString line to get the auto name from the text box * below the Gyro * * You can add additional auto modes by adding additional comparisons to the if-else structure below with additional strings. * If using the SendableChooser make sure to add them to the chooser code above as well. */ void AutonomousInit() { shooter.CalibrateRamp(); shooter.SetRamp(Shoot); autoSelected = *((std::string*)chooser->GetSelected()); //std::string autoSelected = SmartDashboard::GetString("Auto Selector", autoNameDefault); std::cout << "Auto selected: " << autoSelected << std::endl; if(autoSelected == autoNameCustom){ //Custom Auto goes here } else { //Default Auto goes here } } void AutonomousPeriodic() { if(autoSelected == autoNameCustom){ //Custom Auto goes here } else { //Default Auto goes here } } void TeleopInit() { shooter.CalibrateRamp(); shooter.SetRamp(Shoot); // start in the full up position! } void TeleopPeriodic() { if (driver_stick.GetRawButton(THUMB)) { left_drive.Set(driver_stick.GetThrottle() * driver_stick.GetTwist); right_drive.Set(-1 * driver_stick.GetThrottle() * driver_stick.GetTwist); } else { UpdateDrive(); } if(operator_stick.GetRawButton(RAMP_RAISE)) { ramp.Set(1); } else if(operator_stick.GetRawButton(RAMP_LOWER)) { ramp.Set(-1); } else { ramp.Set(0); } if(operator_stick.GetRawButton(THUMB) && !pickupRunning) { shooter.PickUp(); pickupRunning = true; } else if(pickupRunning) { shooter.PickUp(false); pickupRunning = false; } if(driver_stick.GetRawButton(THUMB) && !inverting) { left_drive.SetInverted(!left_drive.GetInverted()); right_drive.SetInverted(!right_drive.GetInverted()); inverting = true; } else if(!driver_stick.GetRawButton(THUMB)) { inverting = false; } float power = (1.0 - operator_stick.GetThrottle()) / 2.0; shooter.SetPower(power); } void TestPeriodic() { lw->Run(); } void UpdateDrive() { //regenerating theta float x = driver_stick.GetX(); float y = driver_stick.GetY(); if (x < 0) { theta = atan(y / x) * -1; } else { theta = atan(y / x); } theta = theta / 6.283185307; // TODO: This math is optimized for humans. Fix it after initial debugging. theta = theta + 1; // I know this is a lot of steps, but I want it to be really readable, because there are at least two stupid mistakes I've yet to find. if (theta != old_theta) { //actually update motors old_theta = theta; if (theta < 0.125) { left_drive.Set(1); right_drive.Set() } } } }; START_ROBOT_CLASS(Robot)