View Single Post
  #6   Spotlight this post!  
Unread 31-01-2014, 16:49
sthreet's Avatar
sthreet sthreet is offline
Registered User
AKA: scott threet
FRC #4692
 
Join Date: Oct 2012
Rookie Year: 2012
Location: Toutle Lake
Posts: 84
sthreet is an unknown quantity at this point
Re: Ultrasonic analog input?

Also having trouble stopping a piston partway through, tried setting both solenoids to true, and both to false.

here is code:
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.AnalogChannel;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class team4692robot extends SimpleRobot 
{
    RobotDrive drive=new RobotDrive(1, 2);
    Joystick left=new Joystick(1);
    Joystick right=new Joystick(2);
    Compressor airCompressor=new Compressor(1, 1);
    Solenoid launchopen=new Solenoid(1);
    Solenoid launchclose=new Solenoid(2);
    Joystick gamepad=new Joystick(3);
    Talon winch=new Talon(3);
    DigitalInput winchstopper=new DigitalInput(2);
    DigitalInput winchstarter=new DigitalInput(3);
    AnalogChannel distance=new AnalogChannel(1);
    Solenoid extendoropen=new Solenoid(3);
    Solenoid extendorclose=new Solenoid(4);
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() 
    {
        int autotimer=0;
        
        airCompressor.start();
        
        while(true && isAutonomous() && isEnabled())
        {
            if(autotimer<100)
            {
                drive.tankDrive(.5, -.5);
            }
            else
            {
                drive.tankDrive(0, 0);
            }
            
            autotimer++;
            Timer.delay(.005);
        }
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() 
    {
        boolean winching=false;
        
        airCompressor.start();
        
        while(true && isOperatorControl() && isEnabled())
        {
            double leftpow=left.getY(); double rightpow=right.getY();
            double powermod=.7;
            if(left.getTrigger())
            {
                powermod+=.1;
            }
            if(right.getTrigger())
            {
                powermod+=.2;
            }
            leftpow*=powermod; rightpow*=powermod;
            
            drive.tankDrive(leftpow, rightpow); 
            
            if(gamepad.getRawButton(1) && winching==false && winchstarter.get())
            {
                winching=true;
            }
            else if(winching==true)
            {
                winch.set(1);
                if(winchstopper.get())
                {
                    winching=false;
                    winch.set(0);
                }
            }
            
            winch.set(gamepad.getRawAxis(1));
            
            launchopen.set(!gamepad.getRawButton(2));
            launchclose.set(gamepad.getRawButton(2));
            
            if(gamepad.getRawButton(3))
            {
                extendoropen.set(true);
                extendorclose.set(false);
            }
            if(gamepad.getRawButton(4))
            {
                extendoropen.set(false);
                extendorclose.set(true);
            }
            
            if(!gamepad.getRawButton(3) && !gamepad.getRawButton(4))
            {
                extendoropen.set(true);
                extendorclose.set(true);
            }
                    
            System.out.println(distance.getAverageVoltage());
            if(distance.getAverageVoltage()<=1)
            {
                drive.tankDrive(.5, .5);
            }
            
            Timer.delay(.005);
        }
    }
    
    /**
     * This function is called once each time the robot enters test mode.
     */
    public void test() 
    {
    
    }
    
    public void robotInit()
    {
        drive.setSafetyEnabled(false);
        Watchdog.getInstance().kill();
    }
}

/*
double left=y; double right=y;
if(x>0)
{
    left+=x;
}
if(x<0)
{
    right+=x;
}
drive.tankDrive(left, right);
*/
__________________
Spoiler for gif:
Reply With Quote