|
|
|
| You've downloaded my heart. |
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Autonomous for gears
Does this work?
package org.usfirst.frc.team1025.robot.commands.VisionM; import org.usfirst.frc.team1025.robot.Robot; import edu.wpi.first.wpilibj.command.Command; /** * */ public class VisionMa extends Command { private double centerX; public VisionMa() { requires(Robot.visionMaybe); requires(Robot.chassisSubsystem); } // Called just before this Command runs the first time protected void initialize() { Robot.visionMaybe.visionThread.start(); } // Called repeatedly when this Command is scheduled to run protected void execute() { synchronized (Robot.visionMaybe.imgLock) { Robot.visionMaybe.centerX1 = this.centerX; } double turn = centerX - (Robot.visionMaybe.IMG_WIDTH / 2); Robot.chassisSubsystem.robotDrive.arcadeDrive(-0.6, turn * 0.005); } // Make this return true when this Command no longer needs to run execute() public boolean isFinished() { if(centerX>0.0) return false; else if(centerX<237.0){ return false; } else{ return true; } } // Called once after isFinished returns true protected void end() { } // Called when another command which requires one or more of the same // subsystems is scheduled to run protected void interrupted() { } } |
|
#2
|
|||
|
|||
|
Re: Autonomous for gears
I'm not sure what you are trying to do with the isFinished() method, but as you have it written right now it will never finish, because centerX will always either be >0 or <237, and the method will return false.
Other than that your logic in execute() looks okay, provided the code that runs in the vision thread works. You may consider using PID to turn the robot instead of feeding values directly into arcade drive method. Hope this helps. |
|
#3
|
||||
|
||||
|
Re: Autonomous for gears
Owing to the fact that we are not robots (well, hopefully. At least, I'm not a robot), it's difficult to tell you if that code "works." Try to run it on an actual robot, especially before build ends in 1.5 weeks
You should also try using the debugger (debug as > wpilib java deploy) if you need step-by-step execution of code. That said,
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|