You've downloaded my heart.
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 06-02-2017, 20:37
verlander13 verlander13 is offline
Registered User
AKA: Ian
FRC #1025 (IMPIS)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Ferndale
Posts: 14
verlander13 is an unknown quantity at this point
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() {
}
}
Reply With Quote
  #2   Spotlight this post!  
Unread 09-02-2017, 18:04
jmcculloch jmcculloch is offline
Jeremy McCulloch
FRC #2485 (W.A.R. (We Are Robot) Lords)
Team Role: Programmer
 
Join Date: May 2016
Rookie Year: 2015
Location: San Diego
Posts: 6
jmcculloch is a jewel in the roughjmcculloch is a jewel in the roughjmcculloch is a jewel in the roughjmcculloch is a jewel in the rough
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 10-02-2017, 01:07
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 420
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
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,
  • Code:
    Robot.visionMaybe.centerX1 = this.centerX;
    Did you mean this to be the other way around?
  • Code:
    synchronized (Robot.visionMaybe.imgLock) {
    synchronized is usually not necessary when you're just reading values (assuming above point is true)
  • Is this what you wanted in isFinished()?
    Code:
    return centerX <= 0 && centerX >= 237;
  • Also with the above code, it's not clear whether it's the behavior you're actually looking for. Could you explain in words?
  • I'm noticing a lot of magic numbers everywhere. You should make those named constants to make your code readable and clean.
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
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 15:34.

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