Log in

View Full Version : NEED Help With turning on the compressor


mechanical_robot
11-02-2014, 12:08
In C++ I just can't figure out how to turn on the compressor. So I have used this code(which is below). But whenever I turn on the robot and enable it, it just makes this very high pitched sound that only certain younger people can hear on the team. I am sure I have it wired correctly too also I have tried pretty much every wire combination for the compressor that I can think of. This isn't the only problem either, since this code is for a mecanum wheel drive whenever I enable the robot one of the talons turn one of the 4 wheels very slowly while the others remain stationary, though this code work very good without our the compressor code in it (one of the wheels don't drift).

Any help appreciated, though I have already gone through the wpilib screen steps. Any example code from previous years would also be appreciated.


Here is the code


#include "WPILib.h"


/**
* This illustrates how to use 4 Talons to drive the robot
* Created from SimpleTemplate
*/
class RobotDemo : public SimpleRobot
{
RobotDrive *myRobot; // robot drive system
Compressor *m_compressor;
Joystick stick; // only joystick
Talon talon_lf;
Talon talon_rf;
Talon talon_lr;
Talon talon_rr;

public:
RobotDemo():
//myRobot(1, 2), // these must be initialized in the same order
stick(1), // as they are declared above.
talon_lf(1),
talon_rf(2),
talon_lr(3),
talon_rr(4)



{
myRobot = new RobotDrive(talon_lf, talon_lr, talon_rf, talon_rr);
myRobot->SetExpiration(0.1);
m_compressor = new Compressor(4, 2);
m_compressor->Start();

// invert as needed
//myRobot->SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
myRobot->SetInvertedMotor(RobotDrive::kFrontRightMotor, true);
//myRobot->SetInvertedMotor(RobotDrive::kFrontLeftMotor, true);
myRobot->SetInvertedMotor(RobotDrive::kRearRightMotor, true);

}

// destructor. Added by brian
~RobotDemo()
{
delete myRobot;
delete m_compressor;

}

/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous()
{
myRobot->SetSafetyEnabled(false);
//myRobot->Drive(-0.5, 0.0); // drive forwards half speed
//Wait(1.0); // for 2 seconds
myRobot->Drive(0.0, 0.0); // stop robot
}

/**
* Runs the motors with arcade steering.
*/
void OperatorControl()
{
printf("4 Talon Test\n");

myRobot->SetSafetyEnabled(true);
while (IsOperatorControl())
{
// arcade drive with one stick
//myRobot->ArcadeDrive(stick); // drive with arcade style

// macadum drive
float gyroAngle = 0.0; // we don't have a gyro connected
myRobot->MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick.GetZ(), gyroAngle);

Wait(0.005); // wait for a motor update time
}
}

/**
* Runs during test mode
*/
void Test() {

}
};

START_ROBOT_CLASS(RobotDemo);

This is the end of the code

E Dawg
11-02-2014, 12:50
Is the code posted here default from WPI? If so, it's an electrical problem. I'd advise triple-checking all of the PWMs. Also, make sure that the relay connected to the compressor is lighting up green when it is supposed to.

mechanical_robot
11-02-2014, 13:27
Is the code posted here default from WPI? If so, it's an electrical problem. I'd advise triple-checking all of the PWMs. Also, make sure that the relay connected to the compressor is lighting up green when it is supposed to.

No thats my team's code not wpilib's

danielms853
11-02-2014, 14:28
You could try to see if the relay works

Initializing : Relay compRelay;
compRelay(COMPRESSOR_RELAY_CHANNEL),

and then set it to turn on if you hit a button

if (stick.GetRawButton(PICK_A_BUTTON))
compRelay.Set(Relay::kOn);
else
compRelay.Set(Relay::kOff);

If this works (side car relay light turns on) on the hardware side, but it doesn't turn on, check your hardware. Also, make sure you connected the relay to a relay port, not a pwm port

Once this works, and you know if the compressor works, and you can debug the auto cutoff switch.

P.S. if you're running a 2013 crio image with 2014 wpi, it won't work, we tried.

sukhjinder564
12-02-2014, 09:45
As stated previously, check your wiring for the compressor and check to make sure your ports are correct. Try looking at the light on the spike relay. If it is green, the compressor should be working. If it is orange, your spike is not getting a signal. Also check if the Spike is plugged in as a relay on the digital sidecar. If it is, check to see if a green LED comes on next to the port that the spike is plugged in. If it comes on, you have a wiring issue. If not, you have a software issue

Alan Anderson
12-02-2014, 11:28
//myRobot(1, 2), // these must be initialized in the same order
stick(1), // as they are declared above.


I'm not quite clear on what the must means in the comments here. Can someone with more insight into the SimpleRobot constructors chime in? What happens when you don't initialize them in the same order?

MrRoboSteve
12-02-2014, 14:16
It doesn't look like a c++ standard requirement.

I don't have the Wind River compiler here at work, but suspect it makes sense if you have dependencies between the fields. For example, if you have four speed controllers and a RobotDrive, it makes sense to construct the speed controllers first, and then the RobotDrive that depends on them.

ekovacs
12-02-2014, 14:45
My team had this problem earlier this year. Try moving this line to OperatorControl instead of where it currently is.


m_compressor->Start();

Bill_B
13-02-2014, 05:34
Wheel drift could be the result of uncalibrated Talons. All of your drive motor talons need to be calibrated as shown in the talon manual. If you swap one out, recalibrate them all again, even if they had been calibrated once upon a time somewhere else. I don't think it applies to swapping motors, but what could it hurt?