Go to Post What we may be looking at is a confusing situation and that can be confusing. - JaneYoung [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, 21:31
hasin5 hasin5 is offline
Registered User
None #4777
 
Join Date: Jan 2013
Location: Canada
Posts: 20
hasin5 is an unknown quantity at this point
Iterative Robot - Need Help!!!

Hi,

This code is iterative robot template based.

If you can spot something that is wrong in the code below, please let me know so I can fix the error. Suggestions would also be nice. Will this code work for the following functions:

1. Mobility
2. Moving wheels through motors
3. Pneumatics -> Piston

Also, for function #3, I know I have two instances of the code. One is the relay version and the other is the solenoid version. Which one do I use?

Also, I'd appreciate it if anyone can look over the parameters to see if they are correct in the constructors.

Here is the code:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
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.Solenoid;
import edu.wpi.first.wpilibj.Victor;

public class RobotTemplate extends IterativeRobot {
    
    int joystickPort = 1;
    
    int leftMotorChannel = 2;
    int rightMotorChannel = 1;
    
    int pressureSwitchChannel = 1;
    //The GPIO channel that the pressure switch is attached to.
    int compressorRelayChannel = 1;
    //The relay channel that the compressor relay is attached to.
    
    int relayModuleNumber = 1;
    int relayChannelNumber = 2;
    
    int victorOneChannel = 3;
    int victorTwoChannel = 4;
    
    RobotDrive theRobot = new RobotDrive(leftMotorChannel, rightMotorChannel);
    Joystick driveStick = new Joystick(joystickPort);
    Compressor mainCompressor = new Compressor(pressureSwitchChannel, compressorRelayChannel);
    Relay spike = new Relay(relayModuleNumber, relayChannelNumber);
    Victor wheelOne = new Victor(victorOneChannel);
    Victor wheelTwo = new Victor(victorTwoChannel);
    
    //if relay doesn't work - use this:
    Solenoid pistonExtract = new Solenoid (1);
    Solenoid pistonRetract = new Solenoid (2);
    
    public void robotInit() {
        mainCompressor.start();
    }

    public void autonomousPeriodic() {
        // will fill later
    }

    public void teleopPeriodic() {
        
        //variables expected to update periodically
        double moveValue = driveStick.getAxis(Joystick.AxisType.kY);
        double rotateValue = driveStick.getAxis(Joystick.AxisType.kX);
        
        theRobot.arcadeDrive(moveValue, -rotateValue); //robot driving
        
        double speed = 1.0; //adjustment back of joystick

        if (driveStick.getTrigger()) { //shooter wheels
            wheelOne.set(speed);
            wheelTwo.set(speed);
        }else{
            wheelOne.set(0.0);
            wheelTwo.set(0.0);
        }
        
        //one variation to work with piston
        if (driveStick.getRawButton(3)) { //top-middle button
            spike.setDirection(Relay.Direction.kForward);
        } else if (driveStick.getRawButton(4)) {
            spike.setDirection(Relay.Direction.kReverse);
        }else{
            spike.set(Relay.Value.kOff);
        }
        
        //which one to choose?
        
        //second variation to work with piston
        if (driveStick.getRawButton(5)) {
            pistonExtract.set(true);
            pistonRetract.set(false);
        }else if (driveStick.getRawButton(6)) {
            pistonRetract.set(false);
            pistonExtract.set(true);
        }else{
            pistonExtract.set(false);
            pistonExtract.set(false);
        }
        
    }
    
    public void testPeriodic() {
        
    }
    
}
Reply With Quote
  #2   Spotlight this post!  
Unread 06-01-2014, 21:56
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,590
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: Iterative Robot - Need Help!!!

Quote:
Originally Posted by hasin5 View Post
Also, for function #3, I know I have two instances of the code. One is the relay version and the other is the solenoid version. Which one do I use?
Either will work. It will depend on what the electrical team hooks it up to. The solenoid module can work with either 12v or 24v solenoids, while a spike relay will only work with 12v solenoids.

You could also use the DoubleSolenoid class, instead of two Solenoid objects.

I don't see anything obviously wrong with the code.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-01-2014, 10:27
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Iterative Robot - Need Help!!!

Quote:
Originally Posted by hasin5 View Post
If you can spot something that is wrong in the code below, please let me know so I can fix the error. Suggestions would also be nice. Will this code work for the following functions:
Even someone with experience will not be able to answer this question perfectly. There are only 2 ways to guarantee that code will work: running it in a (very good) simulator, or running it on the robot. The former is not currently possible with Java, so you'll have to go with the latter. The more you test the code on the actual machine it must run on, the more bugs will become apparent and can be fixed. Your code will fail in some way at some point, so you should do your best to make sure that the failure happens during build season, instead of at a competition.
__________________
I code stuff.
Reply With Quote
  #4   Spotlight this post!  
Unread 14-01-2014, 12:31
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: Iterative Robot - Need Help!!!

Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
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.Solenoid;
import edu.wpi.first.wpilibj.Victor;

public class RobotTemplate extends IterativeRobot {
    
    int joystickPort = 1;
    
    int leftMotorChannel = 2;
    int rightMotorChannel = 1;
    
    int pressureSwitchChannel = 1;
    //The GPIO channel that the pressure switch is attached to.
    int compressorRelayChannel = 1;
    //The relay channel that the compressor relay is attached to.
    
    int relayModuleNumber = 1;
    int relayChannelNumber = 2;
    
    int victorOneChannel = 3;
    int victorTwoChannel = 4;
Its not required, but its good practice to make 'variables' that you don't intend to vary as final. That way they can't be accidentally changed later. e.g.
final int victorOneChannel = 3;

Code:
    
    RobotDrive theRobot = new RobotDrive(leftMotorChannel, rightMotorChannel);
    Joystick driveStick = new Joystick(joystickPort);
    Compressor mainCompressor = new Compressor(pressureSwitchChannel, compressorRelayChannel);
    Relay spike = new Relay(relayModuleNumber, relayChannelNumber);
    Victor wheelOne = new Victor(victorOneChannel);
    Victor wheelTwo = new Victor(victorTwoChannel);
    
    //if relay doesn't work - use this:
    Solenoid pistonExtract = new Solenoid (1);
    Solenoid pistonRetract = new Solenoid (2);
    
    public void robotInit() {
        mainCompressor.start();
    }
You might want to put the initial state of your solenoids, relays, shooter motors, etc. in Init as well.

Code:
    public void autonomousPeriodic() {
        // will fill later
    }

    public void teleopPeriodic() {
        
        //variables expected to update periodically
        double moveValue = driveStick.getAxis(Joystick.AxisType.kY);
        double rotateValue = driveStick.getAxis(Joystick.AxisType.kX);
        
        theRobot.arcadeDrive(moveValue, -rotateValue); //robot driving
        
        double speed = 1.0; //adjustment back of joystick

        if (driveStick.getTrigger()) { //shooter wheels
            wheelOne.set(speed);
            wheelTwo.set(speed);
        }else{
            wheelOne.set(0.0);
            wheelTwo.set(0.0);
        }
Depending on how long your wheels take to get up to speed, and how much driving you do with them on, you may want to toggle the shooter wheel state rather than require the driver to hold it constantly while setting up a shot. (more a customer satisfaction issue than code issue )
Code:
        //one variation to work with piston
        if (driveStick.getRawButton(3)) { //top-middle button
            spike.setDirection(Relay.Direction.kForward);
        } else if (driveStick.getRawButton(4)) {
            spike.setDirection(Relay.Direction.kReverse);
        }else{
            spike.set(Relay.Value.kOff);
        }
Same here.
Code:
        //which one to choose?
        
        //second variation to work with piston
        if (driveStick.getRawButton(5)) {
            pistonExtract.set(true);
            pistonRetract.set(false);
        }else if (driveStick.getRawButton(6)) {
            pistonRetract.set(false);
            pistonExtract.set(true);
        }else{
            pistonExtract.set(false);
            pistonExtract.set(false);
        }
is the duplicate Extract a typo? I think the intent was setting Retract false in one of them.
Code:
        
    }
    
    public void testPeriodic() {
        
    }
    
}
Consider using a separate operator joystick, so the driver won't have to worry about which buttons he's pressing while trying to evade defenders.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-02-2014, 19:03
James Lightfoot James Lightfoot is offline
Programming & Electrical Mentor
FRC #3737 (Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Wayne County, NC
Posts: 21
James Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really niceJames Lightfoot is just really nice
Question Re: Iterative Robot - Need Help!!!

Hello all,

I am a rookie mentor w/ only one experienced programmer. He is learning Java. I am an EE for process controls & automation, but my programming is platform specific. I can read the existing Java code from last year's robot, but we are adding & changing things. I have a few quick questions
1) Where can I find who to use the "iterative Robot" class's methods?
2) Where can I see or program to map the physical I/O to things like Jaguars & ultrasonic sensors?
3) Can I use a relay output point to turn on a motor (w/ the 3 wire pig tail and the 2 power wires) or should I wire them to a PWM point and simply send it a full speed signal?
4) Is there an input that will work with the PWM output of an ultrasonic sensor (300 micro-seconds to 9999 micro-seconds) or do I have to use the voltage analog output from the sensor?
Reply With Quote
  #6   Spotlight this post!  
Unread 01-02-2014, 19:51
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Iterative Robot - Need Help!!!

Quote:
Originally Posted by James Lightfoot View Post
1) Where can I find who to use the "iterative Robot" class's methods?
robotInit() is called when the robot first boots. <mode>Init() is called at the beginning of the given mode, and <mode>Periodic() is called every time a data packet is received from the driver station (in practice, this is every 20ms, or 50 times per second). <mode> is one of teleop, autonomous, test, or disabled.

Quote:
Originally Posted by James Lightfoot View Post
2) Where can I see or program to map the physical I/O to things like Jaguars & ultrasonic sensors?
Here, under "Actuators" and "Sensors".

Quote:
Originally Posted by James Lightfoot View Post
3) Can I use a relay output point to turn on a motor (w/ the 3 wire pig tail and the 2 power wires) or should I wire them to a PWM point and simply send it a full speed signal?
While it is theoretically possible, I am not sure whether that would be legal. Sending the PWM signal from software is not difficult:
Code:
motor.set(Relay.Value.kForward) // relay
motor.set(1); // PWM
Quote:
Originally Posted by James Lightfoot View Post
4) Is there an input that will work with the PWM output of an ultrasonic sensor (300 micro-seconds to 9999 micro-seconds) or do I have to use the voltage analog output from the sensor?
I don't know of any way to read a PWM signal from the cRIO. I would go with the analog signal if possible, as it's pretty simple to program:
Code:
AnalogChannel input = new AnalogChannel(<port>); // change <port> for your setup
input.getAverageVoltage(); // returns analog signal
__________________
I code stuff.
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 13:11.

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