Go to Post I once heard someone say that Dean is "building an army of engineers." I disagree. I think he is building an army of the informed. - Gope [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 12-02-2015, 15:27
Hawk_Prime Hawk_Prime is offline
Registered User
FRC #3229
 
Join Date: Feb 2015
Location: Holly Springs
Posts: 7
Hawk_Prime is an unknown quantity at this point
Coding for a lifter?

Hi, I'm vincent from FRC team 3229, Hawktimus Prime. We just finished our drive program yesterday and now we need to work on the lift mechanism for our robot so we can pick up totes. The only code we have is one Java file called Robot.java in our project. Here's the code:
Code:
package org.usfirst.frc.team3229.robot;


import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.RobotDrive.MotorType;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;

/**
 * This is a demo program showing how to use Mecanum control with the RobotDrive class.
 */
public class Robot extends SampleRobot {
	
    RobotDrive robotDrive;
    Joystick stick;

    // Channels for the wheels
    final int frontLeftChannel	= 3;
    final int rearLeftChannel	= 4;
    final int frontRightChannel	= 2;
    final int rearRightChannel	= 1;
    final int elevator = 6;
    // The channel on the driver station that the joystick is connected to
    final int joystickChannel	= 0;

    public Robot() {
        robotDrive = new RobotDrive(frontLeftChannel, rearLeftChannel, frontRightChannel, rearRightChannel);
        robotDrive.setInvertedMotor(MotorType.kFrontLeft, true);	// invert the left side motors
    	robotDrive.setInvertedMotor(MotorType.kFrontRight, true);
        robotDrive.setExpiration(0.1);

       stick = new Joystick(joystickChannel);
        
        
    }
        

    /**
     * Runs the motors with Mecanum drive.
     */
    public void operatorControl() {
        robotDrive.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
        	
        	// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
        	// This sample does not use field-oriented drive, so the gyro input is set to zero.
            robotDrive.mecanumDrive_Cartesian(stick.getY(), stick.getX(), stick.getZ(), 0);
            
            Timer.delay(0.010);	// wait 5ms to avoid hogging CPU cycles
        }
    }
    
    }
How would I go about just adding something where when you push a button on an xbox controller, a different motor goes? Thanks for the help!
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2015, 15:29
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Coding for a lifter?

What kind of motor controller are you using? Talon, Victor, or Jaguar?
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2015, 15:56
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: Coding for a lifter?

Quote:
Originally Posted by Hawk_Prime View Post

How would I go about just adding something where when you push a button on an xbox controller, a different motor goes? Thanks for the help!
Ultimately I think you'll want to get to

Code:
    ...
    SpeedController elevatorMotor;
    private static final int LIFT_BUTTON=1; //or whatever button raises
    private static final int LOWER_BUTTON=4; //or whatever button lowers
    
    ...
    public Robot() {
        ...
        elevatorMotor=new Talon(elevator);
        ...
    }

    public void operatorControl() {
        robotDrive.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
        	
        	// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
        	// This sample does not use field-oriented drive, so the gyro input is set to zero.
            robotDrive.mecanumDrive_Cartesian(stick.getY(), stick.getX(), stick.getZ(), 0);
            

            if(stick.getRawButton(LIFT_BUTTON)) {
                 elevatorMotor.set(0.5);
            } else if(stick.getRawButton(LOWER_BUTTON)) {
                 elevatorMotor.set(-0.5);
            } else {
                 elevatorMotor.set(0);
            }
            
            Timer.delay(0.010);	// wait 5ms to avoid hogging CPU cycles
        }
    }
but to get there you need some variable representing a SpeedController such as I've shown as elevatorMotor. I showed the code if you use a Talon. If you use something else as Matt was asking about, that line would be different. If you need to call more than just the basic SpeedController interface on you Talon/Jaguar/TalonSRX/etc, you can make the line be

Code:
Talon elevatorMotor=new Talon(elevator);
Then if there is a Talon specific function that is not on the SpeedController interface, you can still call that too. Just trying to keep it simple for you.

I've not used xbox class so I don't know if getRawButton is best way to get buttons or not, or if mappings exist avoiding need for LIFT_BUTTON/LOWER_BUTTON, but using local names with explicit names for lift and lower help keep your code more understandable.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2015, 15:58
Hawk_Prime Hawk_Prime is offline
Registered User
FRC #3229
 
Join Date: Feb 2015
Location: Holly Springs
Posts: 7
Hawk_Prime is an unknown quantity at this point
Re: Coding for a lifter?

Thank you!
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 12:36.

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