[Kstars-devel] branches/kstars/unfrozen/kstars/kstars
Jason Harris
kstars at 30doradus.org
Tue Jul 8 16:56:16 CEST 2008
SVN commit 829464 by harris:
Improved variable-speed slewing. Instead of a kludgy mess of nested if's to
implement a triangular speed profile, I am now using much simpler code to
implement a cosine-shaped profile.
There's a little bit of asymmetry in the profile (i.e., the ending speed doesn't
quite get down to the level of the starting speed, so the ending is a little bit
abrupt). This is a consequence of the speed being determined for position r, and
then applied over the interval (r+dr). The solution is to make the determined
speed the average of speed(r) and speed(r+dr), but I'm not sure it's worth the
extra math. Let me know if the asymmetry is bothersome, or if you have a clean
solution for it...
CCMAIL: kstars-devel at kde.org
M +13 -27 skymap.cpp
--- branches/kstars/unfrozen/kstars/kstars/skymap.cpp #829463:829464
@@ -719,10 +719,9 @@
void SkyMap::slewFocus( void ) {
double dX, dY, fX, fY, r, r0;
- double rslowdown = 0.0;
- double step = 1.0;
+ double step0 = 0.5;
+ double step = step0;
double maxstep = 10.0;
- double grow = 1.1;
SkyPoint newFocus;
@@ -748,9 +747,12 @@
r0 = sqrt( dX*dX + dY*dY );
r = r0;
+ if ( r0 < 20.0 ) { //smaller slews have smaller maxstep
+ maxstep *= (10.0 + 0.5*r0)/20.0;
+ }
while ( r > step ) {
//DEBUG
- //kDebug() << step << ": " << r << ": " << r0 << endl;
+ kDebug() << step << ": " << r << ": " << r0 << endl;
fX = dX / r;
fY = dY / r;
@@ -787,29 +789,13 @@
r = sqrt( dX*dX + dY*dY );
- //rslowdown is set when we have reached the maximum slew speed
- //check to see if we are approaching the target position
- //if so, start slowing down
- if ( rslowdown > 0.0 ) {
- if ( r <= rslowdown && step > 1.0 ) {
- step /= grow;
- }
-
- } else {
- //stop accelerating when we pass the midpoint
- if ( r/r0 < 0.5 && step < maxstep ) { maxstep = step; }
- //accelerate if we're more than 2 steps away and
- //not already at maxstep
- if ( r/step > 2.0 && step < maxstep ) {
- step *= grow;
- if ( step > maxstep ) { step = maxstep; }
- }
- //if we're at maxstep, set rslowdown to the distance
- //traversed so far (this will make a symmetric slowdown)
- if ( step >= maxstep && rslowdown == 0.0 ) {
- rslowdown = 1.25*(r0 - r);
- }
- }
+ //Modify step according to a cosine-shaped profile
+ //centered on the midpoint of the slew
+ //NOTE: don't allow the full range from -PI/2 to PI/2
+ //because the slew will never reach the destination as
+ //the speed approaches zero at the end!
+ double t = dms::PI*(r - 0.5*r0)/(1.05*r0);
+ step = cos(t)*maxstep;
}
}
More information about the Kstars-devel
mailing list