Go to Post FIRST doesn't just prepare you for engineering, it prepares you for life - sciguy125 [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

 
 
 
Thread Tools Rating: Thread Rating: 3 votes, 4.33 average. Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 12-12-2013, 01:04 PM
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Beginner FRC Java Programmer - Help

Quote:
From my understanding, you would use either a Relay or the Solenoid class, but not both. Is that correct? Assuming the OP's solenoid valve is wired to a Spike Relay, the code should work but the Solenoid instance "piston" is not serving any purpose and could be removed.
Yes, I should have paid more attention to the original code.
You would choose either the Relay or Solenoid class to control the output device. Using both classes simultaneously and wiring both hardware outputs to a solenoid valve would be like wiring two motor controllers to a single motor.


Code:
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Victor;

public class MyRobot extends SimpleRobot {

  RobotDrive theRobot;
  SpeedController leftMotor, rightMotor;
  Compressor compressor;
  Relay piston;


  //These need to match your wiring on the DSC
    //Digital Inputs/Outputs
    int compressorSwitchChan = 1;

    //Relay Channels
    int compressorRelayChan  = 1;
    int pistonRelayChan      = 2;

    //PWM Channels
    int leftMotorChan        = 1;
    int rightMotorChan       = 2;

  robotInit() {
    //These need to match the motor type you are using.
    //If you are using Jaguars or Talons, use thier respective class.
    leftMotor = new Victor(leftMotorChan);
    rightMotor = new Victor(rightMotorChan);
    theRobot = new RobotDrive(leftMotor, rightMotor);

    piston = new Relay(pistonRelayChan);

    compressor = new Compressor(compressorSwitchChan, compressorRelayChan);
    compressor.start();
  }

  public void autonomous() { //checks code every 50 seconds        
    theRobot.setSafetyEnabled(false);
    theRobot.drive(-0.5, 0.0);
    Timer.delay(2.0);
    theRobot.drive(0.0, 0.0);

    for (int x = 0; x < 5; x++) {
      piston.set(Relay.Value.kForward);
      timer.delay(1.0);
      piston.set(Relay.Value.kReverse);
      timer.delay(1.0);
    }
  }

  public void operatorControl() {
    //your teleoperated code here...
  }
}
This isn't tested, but should be pretty close to correct.
__________________
http://team2168.org
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 08:08 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