Hawk_Prime
12-02-2015, 15:27
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:
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! :] :)
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! :] :)