Go to Post The most important part anyone can lend is just a hand. - Libby K [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 12-02-2015, 11:09
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Using Hall Effect Sensors

Our team is using hall effect sensor to detect the position of our elevator
This picture should give a good picture of what we are trying to do.
I want to be able to use hall effect sensors to set the height of the elevator fork contraption to the height of one tote or 2 or 3. Using one hall effect sensor mounted on that elevator and mounting the magnets in proper places could work I think.
What I need to know is how to program the team 971 WCP hall effect sensors in java. I currently have a program that uses setpoint PIDSubsystems, but my code crashes when i use the button to set the setpoint. How do you guys go about using hall effect as sensors?
Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2015, 11:30
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 575
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Using Hall Effect Sensors

Your photo didn't display for me.

If you're using something like the WCP hall effect sensor, most teams would treat that as a limit switch, observe its state via a DigitalInput, and count the number of times the switch tripped in code. The PID is a pretty long way to solving your problem.

I would recommend two limit switches on your elevator -- one that trips when you are in the lowest position, and the one that rides on the elevator triggering at the various tote heights (note that I think of the hall effect sensor as a limit switch). This lets you know initially when the elevator is in the lowest position, so that you can correctly determine at what level you're at.

Alternatively, you can always start the robot with the elevator at/below the first position, so that you know your starting position. I'm not a fan of this approach because it doesn't work well if your robot crashes during a match.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2015, 12:35
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
Founder and CEO, DeadMemes Studios
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 370
Poseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud ofPoseidon5817 has much to be proud of
Re: Using Hall Effect Sensors

I'm assuming you are trying to put the Hall Effect sensor on the actual elevator carriage with the magnets mounted on the sides of the rails the elevator rides in (or something similar). I would have a counter that increments or decrements every time you pass a magnet, depending on the current direction of the elevator. Our team is using a Hall Effect sensor with an encoder using the Hall Effect to zero the encoder value. Works like a charm so far.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division
2017 - Team 5817: Return of the bench grinder


Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2015, 13:21
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Using Hall Effect Sensors

A sensor with intermittent points of reference as you describe is not a good candidate for a PID sensor. To use PID, you really want a sensor that provides continuous feedback, like a potentiometer or a range finder. More details here.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2015, 17:39
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: Using Hall Effect Sensors

So I have made a file to make the motor turn the elevator up and down based on the magnet, except that it doesn't react based on the magnet.

Code:
package org.usfirst.frc.team2847.robot.commands;

import org.usfirst.frc.team2847.robot.Robot;

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

/**
 *
 */
public class MagicElevator extends Command {

	double dir;
	double go;
	double more;
	boolean done;

	public MagicElevator(double setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		this.dir = dir + setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
		System.out.println(this);
		Robot.elevator.torro(go);
	}

	// Called repeatedly when this Command is scheduled to run
	protected void execute() {
		if (!Robot.elevator.isHallSet() && dir >= 1) {
			go = 1;
		} else if (!Robot.elevator.isHallSet() && dir <= -1) {
			go = -1;
		} else if (Robot.elevator.isHallSet() && dir >= 1) {
			dir = dir--;
		} else if (Robot.elevator.isHallSet() && dir <= -1) {
			dir = dir++;
		}

		if (dir != 0) {
			done = false;
		} else if (dir == 0) {
			done = true;
		}
		SmartDashboard.putNumber("whaeva", dir);
	}

	// Make this return true when this Command no longer needs to run execute()
	protected boolean isFinished() {
		return done;
	}

	// Called once after isFinished returns true
	protected void end() {
		Robot.elevator.nothing();
	}

	// Called when another command which requires one or more of the same
	// subsystems is scheduled to run
	protected void interrupted() {
		end();
	}
}
I set the setpoint double to -1 or one based on a button and elevator.nothing does what it says and torro spins the elevator motors based on the double inputted.
I also fear that if the elevator gets stopped on the point where the magnet is on it wont move. I want it to function in such a way that pressing my +1 button makes it add up so i can press it 3 times and it increment 3 heights of magnets. I can't figure this out so help is appreciated.
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2015, 11:02
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: Using Hall Effect Sensors

Now i'm able to get the elevator to stop in response to the hall effect sensor, but once it use it to go up i cant press it to go up again, and if i go down i can only go down once. Pressing the button multiple times to add to count does nothing. What am i missing here?

Code:
package org.usfirst.frc.team2847.robot.commands;

import org.usfirst.frc.team2847.robot.Robot;

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

/**
 *
 */
public class MagicElevator extends Command {

	int count;
	int tcount;
	double go;
	boolean done;

	public MagicElevator(int setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		tcount = setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
		System.out.println(this);
	}

	// Called repeatedly when this Command is scheduled to run
	protected void execute() {
		count = count + tcount;

		if (count > 0 && Robot.elevator.isHallSet()) {
			count = (count - 1);
		} else if (count < 0 && Robot.elevator.isHallSet()) {
			count = (count + 1);
		}

		if (count >= 1) {
			go = 1;
		} else if (count <= -1) {
			go = -1;
		}
		Robot.elevator.torro(go);

		if (count != 0) {
			done = false;
		} else if (count == 0) {
			done = true;
		}
		tcount = 0;
		SmartDashboard.putNumber("whaeva", count);
		SmartDashboard.putBoolean("hall", Robot.elevator.isHallSet());
	}

	// Make this return true when this Command no longer needs to run execute()
	protected boolean isFinished() {
		SmartDashboard.putNumber("finsishsjdfiaopsdfsa", count);
		return done;
	}

	// Called once after isFinished returns true
	protected void end() {
		Robot.elevator.nothing();
	}

	// Called when another command which requires one or more of the same
	// subsystems is scheduled to run
	protected void interrupted() {
		end();
	}
}

Last edited by fireXtract : 13-02-2015 at 11:37.
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2015, 12:04
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: Using Hall Effect Sensors

Quote:
Originally Posted by fireXtract View Post
Now i'm able to get the elevator to stop in response to the hall effect sensor, but once it use it to go up i cant press it to go up again, and if i go down i can only go down once. Pressing the button multiple times to add to count does nothing. What am i missing here?
Since your command is ending when done==true, how are you getting another command to run? I think if you tie it to a button with whenPressed() or something like that, it reuses the same object each time. So you have to reinitialize everything in initialize.

Code:
	protected void initialize() {
                //reset fields to values defaulted to on construction
                go=0;
                done=false;
                count=0;
		System.out.println(this);
	}
I suspect you will also want to remember your setpoint and assign that to tcount in the initializer as well since it is being reassigned during execute()

Code:
public class MagicElevator extends Command {

        ...
        int mySetpoint;
        ...

	public MagicElevator(int setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		mySetpoint=setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
                go=0;
                done=false;
                count=0;
		tcount=mySetpoint;
		System.out.println(this);
	}
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2015, 13:39
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: Using Hall Effect Sensors

Quote:
Originally Posted by cstelter View Post
Since your command is ending when done==true, how are you getting another command to run? I think if you tie it to a button with whenPressed() or something like that, it reuses the same object each time. So you have to reinitialize everything in initialize.

Code:
	protected void initialize() {
                //reset fields to values defaulted to on construction
                go=0;
                done=false;
                count=0;
		System.out.println(this);
	}
I suspect you will also want to remember your setpoint and assign that to tcount in the initializer as well since it is being reassigned during execute()

Code:
public class MagicElevator extends Command {

        ...
        int mySetpoint;
        ...

	public MagicElevator(int setpoint) {
		// Use requires() here to declare subsystem dependencies
		requires(Robot.elevator);
		mySetpoint=setpoint;
	}

	// Called just before this Command runs the first time
	protected void initialize() {
                go=0;
                done=false;
                count=0;
		tcount=mySetpoint;
		System.out.println(this);
	}
Thanks cstelter, I did forget to reset the done variable didn't I! I will test your suggestions when I get out of class. Also what would setting another mySetpoint variable do? Would this one carry over between reintialization? Wouldn't it cause the tcount variable to keep adding without resetting on each press of the button that sets the setpoint to (1 -1 or 0)?
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 10:56.

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