View Single Post
  #24   Spotlight this post!  
Unread 03-02-2015, 17:16
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
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:	6
Size:	17.1 KB
ID:	18138  Click image for larger version

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

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

Last edited by Ether : 03-02-2015 at 23:13. Reason: added variable gain option and plots
Reply With Quote