Go to Post the weather always does funny things to people, like when it snows, all these engineers take kids, lock themselves in machine shops & build robots......weird - Lisa Rodriguez [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-01-2014, 18:20
hasin5 hasin5 is offline
Registered User
None #4777
 
Join Date: Jan 2013
Location: Canada
Posts: 20
hasin5 is an unknown quantity at this point
Should this code be working? - Beginner

URGENT:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
public class RobotTemplate extends SimpleRobot {
    RobotDrive theRobot = new RobotDrive(2,1); //#
    Joystick driveStick = new Joystick(1); //# 
    Compressor compressor1 = new Compressor(1,1); //# 
    Relay spike = new Relay (1,1); //#
    Jaguar motorOne = new Jaguar(7); //#
    Jaguar motorTwo = new Jaguar(8); //# 
    Victor victor1 = new Victor(3);
    Victor victor2 = new Victor(4);
    
    public void autonomous() { //checks code every 50 seconds
        theRobot.setSafetyEnabled(false); //allows timer to function
        theRobot.drive(-1, 0.0); //-1 means drive forward
        Timer.delay(2.0); // allows robot to drive forward
        theRobot.drive(1.0, 0.0); // sets drive speed to 0 (stops robot)
        Timer.delay(2.0);
        theRobot.drive(-2, 0.0);
        theRobot.drive(0.0, 0.0);
        compressor1.start();
        //Timer.delay(5.0);
        for (int x = 0; x < 5; x++) {
            spike.set(Relay.Value.kForward);
            Timer.delay(2.0);
            spike.set(Relay.Value.kReverse);
            Timer.delay(2.0);
        }
    }  
    
    public void operatorControl() {
    theRobot.setSafetyEnabled(false); //allows for tele-op to work
        theRobot.arcadeDrive(driveStick.getAxis(Joystick.AxisType.kY), -driveStick.getAxis(Joystick.AxisType.kX)); //functionality to drive robot
        while (isOperatorControl()) {
            compressor1.start();
            theRobot.arcadeDrive(driveStick.getAxis(Joystick.AxisType.kY), -driveStick.getAxis(Joystick.AxisType.kX));
            if (driveStick.getTrigger()){
                victor1.set(1.0);
                victor2.set(1.0);
            //    spike.set(Relay.Value.kForward);
               // spike.set(Relay.Value.kReverse); 
                }
            else {
                victor1.set(0.0);
                victor2.set(0.0);                
            }
            if (driveStick.getRawButton(4)){
                spike.set(Relay.Value.kReverse);
            }
            else{
                spike.set(Relay.Value.kForward);
            }
            }
        

}  
    
 public void test() {
    
}
}
I want to know if two functions will work:

Compressor
Relay/Spike

Currently, the driving is working and the motors are working but the compressor/relay/spike aren't working.

Can someone also explain this:

Sometimes when I edit the compressor object and do something like (2,1) as parameters, it says output not updated often enough repeatedly. When I do 1,1 - the program starts with no errors and everything works except compressor and relay/spike. When I do 1,2 --> IT ALSO works except compressor/relay/spike.... I double checked with the electrical team and they say the port numbers should be 1,1 but I'm not sure. I tested with 2,1 - 1,1 - 1,2 and nothing worked. For some port numbers, it would say output not updated enough and some combinations it wouldn't. Does that mean it does connect to compressor or is a connection loose?

I'm thinking of switching over to iterative because it might be a bit easier.

Last edited by hasin5 : 06-01-2014 at 18:48.
Reply With Quote
  #2   Spotlight this post!  
Unread 06-01-2014, 19:07
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,600
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Should this code be working? - Beginner

You are telling the compressor to use Relay 1, and also allocate Relay 1 as an individual relay. You need to make sure they are using different relays. The code will cause an exception if you allocate a relay twice, which will cause the print of output not updated enough repeatedly. If you scroll back to the beginning, you would see the exception message and traceback.

Make sure to pay attention to the constructors you are using. Relay(1,1) allocates Relay 1 on Digital Module 1. Relay(2,1) allocates Relay 1 on Digital Module 2 (which you more then likely don't have). Relay(1,2) allocates Relay 2 on Digital Module 1. Compressor(1,1) allocates a digital input for the pressure switch on digital input 1 and and a relay on relay 1, using the default digital module (1).

The compressor monitors the pressure switch on the digital input that you specify, and only turns on the compressor when the pressure is low. You need the pressure switch connected for the compressor to come on. Additionally, the start method should not be called in a loop. It creates it's own look in a new task. You should move it before the while loop in teleop.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-01-2014, 19:57
hasin5 hasin5 is offline
Registered User
None #4777
 
Join Date: Jan 2013
Location: Canada
Posts: 20
hasin5 is an unknown quantity at this point
Re: Should this code be working? - Beginner

Do you think if I get this fixed, the code should work?

What if I do:

Compressor compressor1 = new Compressor(1,1); //#
Relay spike = new Relay (1,2); //#
Reply With Quote
  #4   Spotlight this post!  
Unread 06-01-2014, 21:58
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,600
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Should this code be working? - Beginner

Quote:
Originally Posted by hasin5 View Post
Do you think if I get this fixed, the code should work?

What if I do:

Compressor compressor1 = new Compressor(1,1); //#
Relay spike = new Relay (1,2); //#
This will keep there from being conflicts. Make sure your electrical team moves the compressor to relay 1 and the spike to relay 2.

You can look at the relay LEDs on the Digital Sidecar to see if the code is working, even if there isn't a relay connected.
Reply With Quote
  #5   Spotlight this post!  
Unread 07-01-2014, 14:46
hasin5 hasin5 is offline
Registered User
None #4777
 
Join Date: Jan 2013
Location: Canada
Posts: 20
hasin5 is an unknown quantity at this point
Re: Should this code be working? - Beginner

So it's now just the matter of getting the constructor parameters correct?
Reply With Quote
Reply


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 00:42.

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