I don't know what to do. I'm out of ideas. I go to a small, rural high school, that doesn't offer any programming classes, so I've taught myself some coding over the past few months. My code looks fine, and I can't find any mistakes in it, but for whatever reason, nothing on the robot (other than driving) will work. None of the solenoids extend, none of the window motors turn...nothing. I've nested a few print statements throughout my code, but they aren't printing to the console when the robot is running. Can someone take a look at my code, and tell me if there are any glaring mistakes? I know it's a lot to ask, but I don't have any other options at this point. Thank you all so much in advance. (By the way, our robot has a pneumatic-powered arm, sort of like a tractor backhoe or excavator. The arm rotates on a window motor. It also shoots by pushing the ball with a solenoid into 2 spinning motors.)
Code:
#include "WPILib.h"
#include <stdio.h>
class Robot: public IterativeRobot
{
RobotDrive myRobot;
Joystick stick;
Joystick stick2;
DoubleSolenoid solenoid1;
DoubleSolenoid solenoid2;
Solenoid shooter_piston;
Solenoid claw;
Relay shooter_motors;
Relay arm_rotator;
LiveWindow* lw;
int autoloopcounter;
const int button2 = 2;
const int button3 = 3;
const int button4 = 4;
const int button5 = 5;
public:
Robot() :
myRobot(0,1,2,3),
stick(0),
stick2(1),
solenoid1(1, 2),
solenoid2(3, 4),
shooter_piston(5),
claw(6),
shooter_motors(0),
arm_rotator(1),
lw(LiveWindow::GetInstance()),
autoloopcounter(0)
{
myRobot.SetExpiration(0.1);
}
void RobotInit() {
CameraServer::GetInstance()->SetQuality(50);
CameraServer::GetInstance()-> StartAutomaticCapture("cam0");
chooser = new SendableChooser();
chooser->AddDefault(autoNameDefault, (void*)&autoNameDefault);
chooser->AddObject(autoNameCustom, (void*)&autoNameCustom);
SmartDashboard::PutData("Auto Modes", chooser);
}
private:
SendableChooser *chooser;
const std::string autoNameDefault = "Default";
const std::string autoNameCustom = "My Auto";
std::string autoSelected;
void AutonomousInit()
{
autoSelected = *((std::string*)chooser->GetSelected());
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()
{
}
void TeleopPeriodic()
{
///////////ARM CODE////////////////////////////////////////////////
//Code that lifts the entire arm (boom)
double joystick2Y;
joystick2Y = stick2.GetY();
if (joystick2Y > 0.1) {
printf ("Joystick 2 activated for arm");
solenoid1.Set(DoubleSolenoid::kForward); }
else if (joystick2Y < -0.1) {
printf ("Joystick 2 activated for arm (negative)");
solenoid1.Set(DoubleSolenoid::kReverse); }
//Code that extends the arm
if (stick2.GetRawButton(button2)) {
printf ("Button 2 pressed for arm");
solenoid2.Set(DoubleSolenoid::kForward); }
else if (stick2.GetRawButton(button3)) {
printf ("Button 3 pressed for arm");
solenoid2.Set(DoubleSolenoid::kReverse); }
else {
solenoid2.Set(DoubleSolenoid::kOff); }
//Code that rotates the arm
double joystick2X;
joystick2X = stick2.GetX();
if (joystick2X > 0.1) {
printf ("Joystick 2 activated for rotation");
arm_rotator.Set(Relay::kForward); }
else if (joystick2X < -0.1) {
printf ("Joystick 2 activated for rotation (reverse)");
arm_rotator.Set(Relay::kReverse); }
else {
arm_rotator.Set(Relay::kOff); }
//Code that operates the claw
claw.Set(stick2.GetTrigger());
///////////SHOOTER CODE////////////////////////////////////////////////
//Code that operates the shooting motors
if (stick.GetRawButton(button2)) {
printf ("Button 2 pressed for shooter motors");
shooter_motors.Set(Relay::kForward); }
else if (stick2.GetRawButton(button3)) {
printf ("Button 3 pressed for shooter motors");
shooter_motors.Set(Relay::kReverse); }
else {
shooter_motors.Set(Relay::kOff); }
//Code that initiates the shooter piston
shooter_piston.Set(stick.GetTrigger());
/////////DRIVE CODE//////////////////////////////////////////////////////
//Code that drives the robot
myRobot.ArcadeDrive(stick);
}
void TestPeriodic()
{
lw->Run();
}
};
START_ROBOT_CLASS(Robot)