Go to Post Several West Coast teams have attended IRI. I don't know of a single team from east of the Rockies that has attended ANY West Coast off-season. So who is afraid of who? - ChrisH [more]
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 08-02-2017, 18:38
verlander13 verlander13 is offline
Registered User
AKA: Ian
FRC #1025 (IMPIS)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Ferndale
Posts: 12
verlander13 is an unknown quantity at this point
Exclamation Detecting countours

Can anyone explain why my code will not stop once centerX1 is equal to 237?


package org.usfirst.frc.team1025.robot.commands.Vision;

import org.usfirst.frc.team1025.robot.Robot;
import org.usfirst.frc.team1025.robot.subsystems.ChassisS ubsystem;
import org.usfirst.frc.team1025.robot.subsystems.VisionSu bsystem;
import org.usfirst.frc.team1025.robot.subsystems.VisionSu bsystem;

import edu.wpi.first.wpilibj.command.Command;

/**
*
*/
@SuppressWarnings("unused")
public class VisionAuton extends Command {
double centerX1;
double centerX2;
private boolean isCenter = false;

public VisionAuton() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(Robot.visionSubsystem);
requires(Robot.chassisSubsystem);
}

// Called just before this Command runs the first time
protected void initialize() {

}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
synchronized (Robot.visionSubsystem.imgLock) {
Robot.visionSubsystem.centerX1 = this.centerX1;
Robot.visionSubsystem.centerX2 = this.centerX2;
}
// double TargetMidpoint = (centerX2 - centerX1) / 2;
// double disp = (TargetMidpoint - Robot.vision.IMG_WIDTH / 2);
@SuppressWarnings("static-access")
double Turn = centerX1 - (Robot.visionSubsystem.IMG_WIDTH / 2);
//+ centerX2 - (Robot.visionSubsystem.IMG_WIDTH / 2);
// double Turn = (centerX2 - centerX1) / 2 - Robot.vision.IMG_WIDTH / 2;
Robot.chassisSubsystem.getRobotDrive().arcadeDrive (-0.6, Turn * 0.005);

}

// Make this return true when this Command no longer needs to run execute()
public boolean isFinished() {
if(centerX1 == 237.0 + 10){
return isCenter = true;
}
else if(centerX1 == 237.0 - 10){
return isCenter = true;
}
else{
return isCenter == false;
}




}

// 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 08-02-2017, 19:33
MuskieProgramme MuskieProgramme is offline
Registered User
FRC #6420
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2014
Location: Muscatine, IA
Posts: 40
MuskieProgramme is an unknown quantity at this point
Re: Detecting countours

Because you only return true if centerX1 is 247 or 227, not anything in between.

You might go about using the values in between something like this:

Code:
return Math.abs( centerX1 - 237 ) < 10;
What this does is

1) finds the difference between 237 and centerX1
2) gets the absolute value of that
3) compares it to 10. Increasing or decreasing 10 will result in a larger or smaller error margin.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2017, 19:49
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 161
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: Detecting countours

To add on to MuskieProgramme,

Quote:
Originally Posted by verlander13 View Post
Code:
	public boolean isFinished() {
		if(centerX1  == 237.0 + 10){
			return isCenter = true;
		}
		else if(centerX1 == 237.0 - 10){
			return isCenter = true;
		}
		else{
			return isCenter == false;
		}
	}
This doesn't do what you think it does
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote
  #4   Spotlight this post!  
Unread 09-02-2017, 08:37
MuskieProgramme MuskieProgramme is offline
Registered User
FRC #6420
Team Role: Programmer
 
Join Date: Dec 2016
Rookie Year: 2014
Location: Muscatine, IA
Posts: 40
MuskieProgramme is an unknown quantity at this point
Re: Detecting countours

Actually, it does exactly what he thinks it does. It makes isCenter true and then returns true.

http://stackoverflow.com/a/38163971

Quote:
The assignment operator in Java returns the assigned value (like it does, e.g., in c).
Reply With Quote
  #5   Spotlight this post!  
Unread 09-02-2017, 14:00
dvanvoorst dvanvoorst is offline
Registered User
FRC #2771 (Code Red)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Grand Rapids, MI
Posts: 73
dvanvoorst is an unknown quantity at this point
Re: Detecting countours

The problem that people are trying to point out is that your CenterX1 will have to be EXACTLY that value for it to return true. It's not easy to move the robot to the exact pixel position you want, or at least it's typically not necessary to be that exact.
What MuskieProgramme correctly suggests is to give it an acceptable margin of error. In his example code, it will return true if CenterX1 is within 10 pixels of 237. Your acceptable error may be different.
__________________

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 13:18.

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