Go to Post Man, Earthquakes all over the place, Volcanos and clouds of ashes, S&Ps down 25 pts! and now 1114 is first seed and going to probably pick 469... yep, id say the end of the world is near - scessama [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Spotlight this post!  
Unread 13-02-2015, 11:39
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liaison
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 83
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: VEX Ultrasonic Sensor

I can't help you very much with the vision tracking part of the code due to never EVER working with the darn stuff, but I can help with the 6 inch spacing part.

Code:
//After you've found the stack and lined up
double kP = .2
double minSpeed = 0.3;
double maxSpeed = 0.5;
distance = ultra.getRangeInches();
if (distance != 6) {
     while (true) {
          distance = 6 - ultra.getRangeInches(); //Update the distance from our goal (6 inches).
          double p = distance * kP; //Calculate p, which is the speed we want to move at.
          
          //Making sure p is within maxSpeed and minSpeed and correcting it if it isn't.
          if (Math.abs(p) > maxSpeed) {
               p = maxSpeed * (Math.abs(p)/p); //p equals maxSpeed multiplied by the sign of p
          } else if (Math.abs(p) < minSpeed) {
               p = 0; //We're moving too slow, so we're saying we've stopped and hit our goal.
          }

          //Set our motors to p.
          motor1.set(p);
          motor2.set(p);

         //If we're not moving, we've made it to our goal and want to exit this loop.
          if (p == 0) {
               break;
          }
     }
}
Now let me explain what this is and how it works. This is a very simple P loop. How P loops work is a speed is calculated based off of how far you are away from your target. The farther you are away, the faster you move. The speed is calculated by multiplying distance by kP, which you'll need to fine-tune the value of to get it working well. The lower kP is, the more speed scaling you'll see (i.e. the robot slowing down much more as it approaches 6 inches). You'll also want to adjust maxSpeed and minSpeed. maxSpeed is the fastest the robot is allowed to go, and minSpeed is how slow the robot can be going before we say we're arrived at our destination.

This may be all you need, or you may need to expand on this and make it a PI, PD, or PID loop. If you have any issues with this, feel free to ask. I'm happy to help

Last edited by Oromus : 13-02-2015 at 11:46.
Reply With Quote
 


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