|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
and quite possibly an intake if at all possible all posts should be to tell me yes or no and if no what to do to fix it so that my team can be almost done.
![]() package org.usfirst.frc.team6051.robot; import com.ni.vision.NIVision; import com.ni.vision.NIVision.Image; import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.IterativeRobot; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.Talon; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.livewindow.LiveWindow; /** * The VM is configured to automatically run this class, and to call the * functions corresponding to each mode, as described in the IterativeRobot * 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 Robot extends IterativeRobot { private static final int Intake = 0; RobotDrive myRobot; Joystick stick; int autoLoopCounter; private Joystick leftstick; private Joystick rightstick; private GenericHID leftStick; private GenericHID rightStick; private Talon frontright; private Talon frontleft; private Talon rearright; private Talon rearleft; int currSession; int sessionfront; Image frame; /** * This function is run when the robot is first started up and should be * used for any initialization code. */ public void robotInit() { myRobot = new RobotDrive(0,1,2,3); setLeftstick(new Joystick(0)); setRightstick(new Joystick(1)); frontright = new Talon(1); frontright.set(.5); frontleft = new Talon(2); frontleft.set(.5); rearright = new Talon(3); rearright.set(.5); rearleft = new Talon(4); rearleft.set(.5); frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0); sessionfront = NIVision.IMAQdxOpenCamera("cam1", NIVision.IMAQdxCameraControlMode.CameraControlMode Controller); currSession = sessionfront; NIVision.IMAQdxConfigureGrab(currSession); } /** * This function is run once each time the robot enters autonomous mode */ public void autonomousInit() { autoLoopCounter = 0; myRobot.drive(0.5, 0.0); } /** * This function is called periodically during autonomous */ public void autonomousPeriodic() { if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds) { myRobot.drive(0.5, 0.0); // drive forwards half speed autoLoopCounter++; } else { myRobot.drive(0.0, 0.0); // stop robot } } /** * This function is called once each time the robot enters tele-operated mode */ public void teleopInit(){ } /** * This function is called periodically during operator control */ public void teleopPeriodic() { myRobot.setSafetyEnabled(true); while (isOperatorControl() && isEnabled()) { myRobot.tankDrive(leftStick, rightStick); System.out.println(leftStick.getY()); System.out.println(rightStick.getY()); leftStick.getRawAxis(0); Timer.delay(0.005) ; LiveWindow.run(); rightStick.getPOV(Intake); }} /** * This function is called periodically during test mode */ public void testPeriodic() { LiveWindow.run(); } public Joystick getLeftstick() { return leftstick; } public void setLeftstick(Joystick leftstick) { this.leftstick = leftstick; } public Joystick getRightstick() { return rightstick; } public void setRightstick(Joystick rightstick) { this.rightstick = rightstick; } } Last edited by Heber Hooper : 02-22-2016 at 04:35 PM. Reason: To add the code |
|
#2
|
|||
|
|||
|
Re: Will this code successfully run my robot as a tank drive also a single forward ca
There is a problem in your robotInit where you allocate PWM channels 0-3 when constructing your RobotDrive object and then allowcate PWM channels 1-4 when creating your talons, try changing it to:
Code:
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
setLeftstick(new Joystick(0));
setRightstick(new Joystick(1));
frontright = new Talon(1);
frontleft = new Talon(2);
rearright = new Talon(3);
rearleft = new Talon(4);
myRobot = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
// I would comment out the vision stuff for now, until you are driving
//frame = NIVision.imaqCreateImage(NIVision.ImageType.IMAGE_ RGB, 0);
//sessionfront = NIVision.IMAQdxOpenCamera("cam1", NIVision.IMAQdxCameraControlMode.CameraControlMode Controller);
//currSession = sessionfront;
//NIVision.IMAQdxConfigureGrab(currSession);
}
Code:
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
myRobot.tankDrive(leftStick, rightStick);
// Instead of System.out.prinlnt(), you might want to try:
// SmartDashboard.putNumber("Left Stick Y", leftStick.getY());
System.out.println(leftStick.getY());
System.out.println(rightStick.getY());
// Did you want to do something with the value returned?
// leftStick.getRawAxis(0);
// This only reads the angle of POV 0 from the right joystick,
// you will need to add code if you want to do something with
// the value returned
int intakeMode = rightStick.getPOV(Intake);
}
|
|
#3
|
||||
|
||||
|
Re: Will this code successfully run my robot as a tank drive also a single forward ca
Some notes:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|