View Single Post
  #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: 90
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