Go to Post It sounds like "whirr" if you do it right, and "clack clack grunge snap @$@%^!!" if you don't. - dtengineering [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 24-03-2015, 13:16
DeeWBee DeeWBee is offline
Registered User
FRC #3630
 
Join Date: Feb 2011
Location: Breck
Posts: 3
DeeWBee is an unknown quantity at this point
Updating Speed Using Ultrasonic Sensors

I am trying to create code that will slow down the robot as it gets closer to an object.

So far I have been able to write code that will stop the robot using an "if" statement with the conditional being the range as measured by sonar.


Code:
if(sonar.getRangeInches() < 40) {
             motor.stop();
However, when I modify the code such that I want to change the speed on approach, I get "robotDrive...output not updated enough". Any ideas? I've gotten the code to run by disabling the motor safety, but the sensitivity doesn't change at all.


Code:
if(sonar.getRangeInches() < 40) {
            driveTrain.setSensitivity(0.5)
          elseif(sonar.....<30){
            driveTrain.setSensitivty(0.25)......
Reply With Quote
  #2   Spotlight this post!  
Unread 24-03-2015, 14:23
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Updating Speed Using Ultrasonic Sensors

* Put your robot on blocks so it wont drive.
* Add print statements to your code that lists the distance and motor output value for each loop itteration.
* Run your code while moving an object in front of the ultrasonic sensor.

There's got to be a case where your if/else logic doesn't result in the motor.drive() method being called.


Also, why are you using the setSensitiviy method, that affects turning not rate of travel.
See: http://team2168.org/javadoc/edu/wpi/...obotDrive.html
__________________
http://team2168.org

Last edited by otherguy : 24-03-2015 at 14:29. Reason: question set sensitivity use
Reply With Quote
  #3   Spotlight this post!  
Unread 24-03-2015, 19:41
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 93
JacobD is an unknown quantity at this point
Re: Updating Speed Using Ultrasonic Sensors

You can also do something like this. It starts a linear deceleration of the magnitude for mecanum drive. Just change out the numbers and the drive base and it will be fine.

Code:
    		double counter, startDecelDistance, stopDistance, differenceInDistance;
    		
    		startDecelDistance = 20;
    		stopDistance = 40;
    		
    		differenceInDistance = Math.abs(stopDistance-startDecelDistance);
    		
    		while(sonar.getRangeInches() < startDecelDistance && sonar.getRangeInches() > stopDistance) {
    			counter= Math.abs(startDecelDistance - sonar.getRangeInches()) / differenceInDistance;
    			myRobot.mecanumDrivePolar(counter, 0, 0);
    		}
    			myRobot.mecanumDrivePolar(0,0,0);
Reply With Quote
  #4   Spotlight this post!  
Unread 29-03-2015, 14:43
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Updating Speed Using Ultrasonic Sensors

If you're using CammandBased java, you should take a look at Gearsbot. It uses PID control to move to a certain distance away from an object and stop, which seems to be exactly what you're trying here.
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #5   Spotlight this post!  
Unread 29-03-2015, 15:00
GeeTwo's Avatar
GeeTwo GeeTwo is online now
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,687
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: Updating Speed Using Ultrasonic Sensors

You might be better off overriding the set method of your motor controller. If you do it there, you only have to do it once, and not worry about it anywhere else.

You may also want to only reduce the throttle if the applied voltage will push you towards the wall, but allow full throttle to push you away from the wall.
__________________

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
  #6   Spotlight this post!  
Unread 29-03-2015, 15:32
engunneer's Avatar
engunneer engunneer is offline
Alumni turned Mentor
AKA: Branden Gunn
FRC #4761
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1996
Location: Reading, MA
Posts: 869
engunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond reputeengunneer has a reputation beyond repute
Re: Updating Speed Using Ultrasonic Sensors

In addition to everyone else's suggestions, the problem you are having is mostly from the structure of your if statement
Code:
if(sonar.getRangeInches() < 40) {
            driveTrain.setSensitivity(0.5)
          elseif(sonar.....<30){
            driveTrain.setSensitivty(0.25)......
remember that if an if statement returns true, the other elses aren't always evaluated
What you wrote
Code:
If it's <40, then do something
If it's not <40 but is <30, do something else (this can't happen!)
try instead building from one direction to the other
Code:
if(sonar.getRangeInches() >= 40) 
{
            driveTrain.setSensitivity(1);
}
else if(sonar.....>= 30)
{
            driveTrain.setSensitivity(0.5);
}
else /*if(sonar.....< 30)*/
{
            driveTrain.setSensitivty(0.25);
}
you can also do it mathematically (y=mx+b)
Code:
driveTrain.setSensitivty(sonar.getRangeInches() / 40)
__________________
Student FRC23 (1996-1999), Mentor FRC246 (2000), Mentor FRC1318 (2007-2009), Mentor FRC93 (2011), Mentor FRC2151 (2012), Mentor FRC23 (2013), Mentor FRC4761 (2014-2017)
1998 - National Chairman's Award and Woodie Flowers Award (FRC23, Mike Bastoni ) | 2007 - PNW SF (488, 1595) | 2008 - Oregon RCA - Seattle #2 Seed, SF (488, 1696) | 2009 - Oregon #1 Seed, Winners (1983, 2635) - Seattle SF (945, 2865) - Galileo #2 Seed, SF (973, 25) | 2012 Midwest F (111, 71) | 2014 RIDE Winners (78, 125), Inspector - NEU #24, QF (3479, 3958) - NECMP #35 | 2015 Reading #11, SF (1058, 190), Inspector - RIDE #17, QF(4055, 5494), Inspector - NECMP #57 | 2016 Reading #4, SF (133, 4474), DCA, Inspector - Ride #22, SF (1735, 2067), Creativity, Inspector - NECMP #48, RCA - Archimedes
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:06.

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