|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
problem with motors and programs
When we run the robot, we have button 3 and button 2 on the right Joystick move the arm. but when we try it doesnt work. The speed controller turns red when we try, but w/o the codes its yellow. Anyhelp is our code wrong, cuz our tankdrive works
package org.team640; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.SimpleRobot; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.camera.AxisCamera; import edu.wpi.first.wpilibj.camera.AxisCameraException; import edu.wpi.first.wpilibj.image.ColorImage; import edu.wpi.first.wpilibj.image.NIVisionException; public class FRC2011Team640 extends SimpleRobot { private final double TARGET_SCORE_THRESHOLD = .01; private RobotDrive robotDrive = new RobotDrive(1,2); private Victor arm = new Victor (3); private Joystick stickLeft = new Joystick(1); private Joystick stickRight = new Joystick(2); private AxisCamera cam; private TrackerDashboard trackerDashboard = new TrackerDashboard(); public FRC2011Team640() { getWatchdog().setExpiration(0.5); initializeTargetting(); } public void autonomous() { getWatchdog().setEnabled(false); for (int i = 1; i <=4; i = i +1) { robotDrive.drive(0.5,0.0); Timer.delay(2.0); robotDrive.drive(0.0,0.0); Timer.delay (2.0); } } private void processTarget() { try { System.out.println("Trying to obtain image"); if (cam.freshImage()) {// && turnController.onTarget()) { System.out.println("Have fresh image"); ColorImage image = cam.getImage(); Thread.yield(); Target[] targets = Target.findCircularTargets(image); Thread.yield(); image.free(); if (targets.length <= 100 || targets[10].m_score < TARGET_SCORE_THRESHOLD) //length == 0 (original) { System.out.println("No target found"); Target[] newTargets = new Target[targets.length + 1]; newTargets[0] = new Target(); newTargets[0].m_majorRadius = 10; // radius = 0 (original) newTargets[0].m_minorRadius = 1; newTargets[0].m_score = 2; for (int i = 1; i < targets.length; i++) { newTargets[i + 1] = targets[i]; } trackerDashboard.updateVisionDashboard(0.0, 0.0, 0.0, 0.0, newTargets); } else { System.out.println("HAVE TARGET!!!!!"); System.out.println(targets[0]); System.out.println("Target Angle: " + targets[0].getHorizontalAngle()); trackerDashboard.updateVisionDashboard(0.0, 0.0, 0.0, targets[0].m_xPos / targets[0].m_xMax, targets); } } else { System.out.println("No image"); } } catch (NIVisionException ex) { ex.printStackTrace(); } catch (AxisCameraException ex) { ex.printStackTrace(); } } private void initializeTargetting() { Timer.delay(10.0); cam = AxisCamera.getInstance(); cam.writeResolution(AxisCamera.ResolutionT.k320x24 0); cam.writeBrightness(0); } public void moveArm1() { getWatchdog().feed(); arm.set(1.0); Timer.delay(0.4); } public void moveArm2 () { getWatchdog().setEnabled(true); arm.set(1.0); Timer.delay(3.5); } public void operatorControl() { getWatchdog().setEnabled(true); while (isEnabled() && isOperatorControl()) { if(stickLeft.getRawButton(3)) { moveArm1();} else if (stickLeft.getRawButton(2)) { moveArm2(); } } } } |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|