Go to Post I betcha the FIRST officials in the know come in here from time to time and either gasp and think of how to make next year's clue harder or fall off their chair laughing. - Sparks333 [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #21   Spotlight this post!  
Unread 02-03-2015, 05:16 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,997
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: H-Drive Programming


Instead of using arctangent and exponential functions, why not just multiply the X axis by a factor of 4, clip it at 1, and normalize the resulting X,Y pair?


Code:


void adjust(float Xj, float Yj, float *Xa, float *Ya){

	float mag;

	*Ya=Yj;
	
	if (Xj<=-0.25) *Xa=-1; 
	else if (Xj<0.25) *Xa=4.0*Xj;
	else *Xa=1.0;

	// normalize adjusted values:
	mag=sqrt(*Xa**Xa+*Ya**Ya);
	if (mag>1) {*Xa/=mag; *Ya/=mag;}
}
See attached Excel spreadsheet. The 100 tab shows an overview of adjusted XY pairs (cyan cells) for the entire first quadrant. The 25 tab zooms in for a closer look for small joystick values.

The attached plot shows a family of Xa vs Xj curves for Yj=0 to 1.


Or you could make the X gain a function of Yj, like so:

Code:


void adjust(float Xj, float Yj, float *Xa, float *Ya){

	float mag, gain;

        gain=1+3*Yj;

	*Ya=Yj;
	
        *Xa=gain*Xj;
        if (*Xa>1) *Xa=1;
        else if (*Xa<-1) *Xa=-1;

	// normalize adjusted values:
	mag=sqrt(*Xa**Xa+*Ya**Ya);
	if (mag>1) {*Xa/=mag; *Ya/=mag;}
}
See attached plots for Xa vs Xj for Yj=0 to 1
and Ya vs Yj for Xj=0 to 1


Attached Thumbnails
Click image for larger version

Name:	Xa vs Xj  for Yj=0 to 1.png
Views:	5
Size:	17.1 KB
ID:	18138  Click image for larger version

Name:	Xa vs Xj, Yj=0 to 1 (variable gain).png
Views:	7
Size:	48.3 KB
ID:	18139  Click image for larger version

Name:	Ya vs Yj, Xj=0 to 1 (variable gain).png
Views:	5
Size:	17.0 KB
ID:	18140  
Attached Files
File Type: xls XY.xls (47.0 KB, 8 views)

Last edited by Ether : 02-03-2015 at 11:13 PM. Reason: added variable gain option and plots
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 08:16 AM.

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