Difference between revisions of "Thread:Talk:Precise Prediction/NanoSim"

From Robowiki
Jump to navigation Jump to search
(New thread: NanoSim)
 
(changed NanoSim)
 
Line 2: Line 2:
  
 
<syntaxhighlight>
 
<syntaxhighlight>
class NanoSim
+
class NanoSim {
{
 
 
     public static double x, y, h, v;
 
     public static double x, y, h, v;
     public static void simulate(double att, double d, double maxv) {
+
   
       if (d == 0) d = -Math.signum(v);
+
     public static double simulate(double att, double d, double maxv) {
 +
       if (d == 0) d = Math.signum(v);
 
       if (v * d < 0) d *= 2;
 
       if (v * d < 0) d *= 2;
 
       if (((d = v + d) * v) < 0) d /= 2.0;
 
       if (((d = v + d) * v) < 0) d /= 2.0;
       x += Math.sin(h = Utils.normalNearAbsoluteAngle(h + limit(Rules.getTurnRateRadians(v), att))) * (v = limit(maxv, d));
+
      double r = limit(Rules.getTurnRateRadians(v), att);
 +
       x += Math.sin(h = Utils.normalNearAbsoluteAngle(h + r)) * (v = limit(maxv, d));
 
       y += Math.cos(h) * v;
 
       y += Math.cos(h) * v;
 +
      return att - r;
 
     }
 
     }
  
Line 17: Line 19:
 
     }
 
     }
 
}
 
}
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
At least it makes the same as the old NanoSim. Not sure if it is sound i have to check it later a little more seriously. But eventually it helps a little and shows the direction.
 
At least it makes the same as the old NanoSim. Not sure if it is sound i have to check it later a little more seriously. But eventually it helps a little and shows the direction.
 +
 +
EDIT: Well after playing with the LocationBot it turned out i had to change it. Simulate now gives the rest att back and can be used for the next step. If the direction (d) is correct it works quite nice (there is a little glitch if the bot begins to get straight but most of the time he is right and ends up at the the predicted coordinates). One issue is still to find the right direction. Has anyone an idea how to get the right direction?

Latest revision as of 17:16, 15 September 2012

Hi. Not sure if this is still in progress, but i touched it a little and came up with this (128 byte and max user velocity) :

class NanoSim {
    public static double	x, y, h, v;
    
    public static double simulate(double att, double d, double maxv) {
      if (d == 0) d = Math.signum(v);
      if (v * d < 0) d *= 2;
      if (((d = v + d) * v) < 0) d /= 2.0;
      double r = limit(Rules.getTurnRateRadians(v), att);
      x += Math.sin(h = Utils.normalNearAbsoluteAngle(h + r)) * (v = limit(maxv, d));
      y += Math.cos(h) * v;
      return att - r;
    }

    private static double limit(double minmax, double value) {
      return Math.max(-minmax, Math.min(value, minmax));
    }
}

At least it makes the same as the old NanoSim. Not sure if it is sound i have to check it later a little more seriously. But eventually it helps a little and shows the direction.

EDIT: Well after playing with the LocationBot it turned out i had to change it. Simulate now gives the rest att back and can be used for the next step. If the direction (d) is correct it works quite nice (there is a little glitch if the bot begins to get straight but most of the time he is right and ends up at the the predicted coordinates). One issue is still to find the right direction. Has anyone an idea how to get the right direction?