Go to Post The more women we have as 'rock stars' in FIRST, the more girls we'll see celebrating math and science and the doors they can open. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 26-05-2011, 18:28
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by ratdude747 View Post
I crunched both examples and got 360. maybe my calculator got it wrong, but I think the floor is the issue since it will gives either 0 or 1 and thus either 0 or 360.
For Example1,

0.5+(-357)/360 is equal to -0.4917

The floor of -0.4917 is -1.

Are you saying that your calculator returned 0 or 1, instead of -1 ??






Last edited by Ether : 26-05-2011 at 18:56.
Reply With Quote
  #17   Spotlight this post!  
Unread 26-05-2011, 18:54
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by ratdude747 View Post
questions?
Yes.

1) What encoder are you using, and why did you have to do this:

Quote:
use sin and asin to make all values between 0 and 2pi.

2) If the (X,Y, Z) joystick values are (0.2, -0.5, 0.25), would you please crank those numbers through your code and post the 4 target wheel speeds and wheel steering angles that your code calculates.


3) What is the wheelbase and trackwidth of your vehicle




Last edited by Ether : 26-05-2011 at 19:01.
Reply With Quote
  #18   Spotlight this post!  
Unread 26-05-2011, 20:29
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: PID crossing 0

1. US digital MA3 encoders. it is to allow for the calibration to work So anything above 2pi is converted to values in the range of 0 to 2 pi. otherwise you might have negative values and vales not going all the way to 2pi.
2.I will when i have time and my graphing calculator.


3. I am not 100% sure but it is close to the scale of a wb=38 and tw=28 (frame was close to max size, wheels in corners). assume that scale for #2's values.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
Reply With Quote
  #19   Spotlight this post!  
Unread 26-05-2011, 21:21
Strants Strants is offline
Registered User
AKA: Gavin Stewart
FRC #1977
Team Role: College Student
 
Join Date: Dec 2010
Rookie Year: 2010
Location: Colorado
Posts: 11
Strants is an unknown quantity at this point
Re: PID crossing 0

If you plan to use vectors, you could actually just use some properties of vectors to find the target angle. Let U be the vector in the direction the wheels are currently facing, and V be the vector in the direction you want the wheels to face. Assuming U and V are unit vectors (that is, they have a length of one), the angle between then (let's call it Q) is found by the equation Q = acos((Ux*Vx)+(Uy*Vy)). Because acos returns a value between 0 and pi, we can subtract Q from pi if Q is greater than pi/2 (because, if Q is greater than pi/2, it is quicker to turn the wheels to face in the opposite direction and rotate them backwards). After this set, Q is between 0 and pi/2, but we don't know which direction to rotate in. Assume a positive value of Q corresponds to a counterclockwise rotation, we can then give Q the same sign as the expression (Ux * Vy - Uy * Vx), which is always positive if the rotation required to move U to V is counterclockwise, and negative if the rotation is clockwise. This will give you the shortest counterclockwise rotation, with negative magnitude benefits.

In psuedo-C:
Code:
//To start, we assume magnitude is positive
bool neg_mag_benefits = false; 
double getCorrectionAngle(double currentAngle, double destinationAngle) {
  double currentX = cos(currentAngle);
  double currentY = sin (currentAngle);
  double destinationX = cos(destinationAngle);
  double destinationY = sin(destinationAngle);
  double correctionAngle = acos(currentX * destinationX + currentY * destinationY);
  //correctionAngle is in the range 0 to PI.
  double crossProd = currentX * destinationY - currentY * destinationX;
  if(correctionAngle > PI/2) {
    neg_mag_benefits = true; //We will be turning the wheels in a negative direction
    correctionAngle = PI - correctionAngle; //In range 0 to PI/2
  }
  correctionAngle *= abs(crossProd)/crossProd;
  return correctionAngle;
}
Reply With Quote
  #20   Spotlight this post!  
Unread 26-05-2011, 21:32
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by ratdude747 View Post
So anything above 2pi is converted to values in the range of 0 to 2 pi
Yes, but why are you using sine and arcsine to do this?


Quote:
Originally Posted by ratdude747 View Post
2.I will when i have time and my graphing calculator.
I thought you had working code. Can't you just run the code?





Last edited by Ether : 26-05-2011 at 21:39.
Reply With Quote
  #21   Spotlight this post!  
Unread 26-05-2011, 22:38
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by Strants View Post
If you plan to use vectors, you could actually just use some properties of vectors to find the target angle. Let U be the vector in the direction the wheels are currently facing, and V be the vector in the direction you want the wheels to face. Assuming U and V are unit vectors (that is, they have a length of one), the angle between then (let's call it Q) is found by the equation Q = acos((Ux*Vx)+(Uy*Vy)). Because acos returns a value between 0 and pi, we can subtract Q from pi if Q is greater than pi/2 (because, if Q is greater than pi/2, it is quicker to turn the wheels to face in the opposite direction and rotate them backwards). After this set, Q is between 0 and pi/2, but we don't know which direction to rotate in. Assume a positive value of Q corresponds to a counterclockwise rotation, we can then give Q the same sign as the expression (Ux * Vy - Uy * Vx), which is always positive if the rotation required to move U to V is counterclockwise, and negative if the rotation is clockwise. This will give you the shortest counterclockwise rotation, with negative magnitude benefits.

If you don't use vectors, you could do the following:

Let U be the angle (in radians) in the direction the wheels are currently facing,
and V be the angle in the direction you want the wheels to face.

Assuming U and V are both measured in the same direction from the same zero reference,
the angle between them (let's call it Q) is found by the equation:

Q = (V-U) - 2pi*floor(0.5+(V-U)/2pi);

Because the above returns a value for Q between -pi and pi,
it tells you which direction to rotate as well as how much to rotate.

If you want to add logic to reverse direction,
that is straightforward to do at this point.

Be aware that it is not necessarily true that steering angle changes
greater than pi/2 are best handled by reversing wheel speed direction
.

It depends on many factors, such as the present value of wheel speed,
and the relative dynamic response of your wheel speed vs steering angle.






Last edited by Ether : 26-05-2011 at 22:52.
Reply With Quote
  #22   Spotlight this post!  
Unread 27-05-2011, 07:11
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: PID crossing 0

it does use vectors.

I do not know c or c++ for the record.

it *should* work... but I currently do not have access to robot and if i did, it needs its crio re-installed among other control system parts. bottom line is that It may be a while until I can test it.

I used sin and asin since it always puts it in the correct range. you could also use cos and acos.
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
Reply With Quote
  #23   Spotlight this post!  
Unread 27-05-2011, 15:50
Strants Strants is offline
Registered User
AKA: Gavin Stewart
FRC #1977
Team Role: College Student
 
Join Date: Dec 2010
Rookie Year: 2010
Location: Colorado
Posts: 11
Strants is an unknown quantity at this point
Re: PID crossing 0

Quote:
Originally Posted by ratdude747 View Post
I used sin and asin since it always puts it in the correct range. you could also use cos and acos.
Actually, asin will always return a value between -pi/2 and pi/2, while acos will always return a value between 0 and pi. If you want an angle between 0 and 2pi, you have to consider both acos and asin, as alone neither gives enough information to determine the angle*.

If you want to use trig, this method could work:

Let U be the raw angle given by the encoder, and Q be that same angle put in the range [0, 2pi].

If sin(U) >= 0, then Q = acos(cos(U))
Otherwise, Q = 2pi - acos(cos(U))

* In fact, for sin(x) = k, 0 <= x < 2pi, there are two possible values for x (barring x = pi/2 or 3pi/2). Likewise, cos(x) = m also has two values (barring x = 0 or x = pi). The possible value represented in both equations is the true value of x.
Reply With Quote
  #24   Spotlight this post!  
Unread 27-05-2011, 16:37
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: PID crossing 0

i see the point... perhaps my best bet is to use mechanical calibration instead...
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.
Reply With Quote
  #25   Spotlight this post!  
Unread 27-05-2011, 16:42
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by Strants View Post
Let U be the raw angle given by the encoder, and Q be that same angle put in the range [0, 2pi].

If sin(U) >= 0, then Q = acos(cos(U))
Otherwise, Q = 2pi - acos(cos(U))
Yikes! use this:

U = U - 2pi*floor(U/2pi)



Reply With Quote
  #26   Spotlight this post!  
Unread 27-05-2011, 22:37
ratdude747's Avatar
ratdude747 ratdude747 is offline
Official Scorekeeper
AKA: Larry Bolan
no team
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Madison, IN
Posts: 1,064
ratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond reputeratdude747 has a reputation beyond repute
Re: PID crossing 0

Quote:
Originally Posted by Ether View Post
Yikes! use this:

U = U - 2pi*floor(U/2pi)


i checked that. looks good. thank you!

I tried using a formula node for that but i guess you have to declare variables in those... the only 2 text languages i really know are pbasic (unrelated: didn't older IFI contollers use that?) and ti-8x code.

although the team's main programmer hates my lack of formula nodes, using discrete math blocks will have to do for now...
__________________
Dean's List Semi-finalist 2010
1747 Harrison Boiler Robotics 2008-2010, 2783 Engineers of Tomorrow 2011, Event Volunteer 2012-current

DISCLAIMER: Any opinions/comments posted are solely my personal opinion and does not reflect the views/opinions of FIRST, IndianaFIRST, or any other organization.

Last edited by ratdude747 : 28-05-2011 at 10:06.
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 11:00.

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