Go to Post We need to celebrate great things because good enough isn't inspiring. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 02-26-2016, 07:28 PM
FRC3220 FRC3220 is offline
Registered User
no team
 
Join Date: Feb 2016
Location: Spangle
Posts: 11
FRC3220 is an unknown quantity at this point
Motors/solenoids won't work; Can't print to console

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)
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:24 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi