【问题标题】:How do i calculate the orientation/direction and the velocity of a Sun Spot?如何计算太阳黑子的方向/方向和速度?
【发布时间】:2014-12-09 16:09:49
【问题描述】:

我正在我的太阳黑子上试验加速度计。 我试图通过从 X 轴和 Y 轴测量加速度计的值来计算速度,但它们对我来说似乎是随机的。

获取运动的值和方向/方向并计算其速度的正确方法是什么?

这是我的代码:

while (true) {

        try {
             offset=Math.sqrt(accel.getAccelX()*accel.getAccelX()+accel.getAccelY()*accel.getAccelY());
               if(offset<0.1 && offset>-0.1)
                   offset=0;

            v=(offset+ ((offset-anterior))/2)*0.2; //0.2 is 200millisecs
            anterior=offset;
            Utils.sleep(200);//5 reads per secound
          }}...

更新 例如,我将太阳黑子朝一个方向移动,变量 v(velocity) 按随机顺序(非顺序)为我提供从负数到 7ms 的值。如果改变运动的方向,它不会像我预期的那样给我负值。

例子:(如果我把它移到我的右边)

v =0.4771031167950723
v =0.4771031167950723
v =-0.15903437226502407
v =-0.15903437226502407
v =0.33841556285063856
v =0.33841556285063856
v =0.7397145777969039

提前致谢。

【问题讨论】:

  • 它们在什么方面看起来是随机的?你并没有真正告诉我们问题出在哪里。
  • 对不起,我更新了问题
  • 您多久轮询一次数据?您可能需要在一段时间内取某种平均值,以消除硬件内部的波动
  • 什么是“太阳黑子”(或“太阳黑子”)?该标签与this 相关,这似乎与您的报价无关。
  • 速度是加速度的积分。所有加速度样本的总和将给出相对于未知初始速度的速度,或者只是速度是你假设它最初是静止的。

标签: java embedded accelerometer physics


【解决方案1】:

就像@John Story 所说的那样,处理这个问题的最佳方法是进行平均。 太阳黑子加速度计非常不稳定,不适合精确的速度预测。

无论如何这是我能做的最好的代码

double v=0;
    double anterior=0;

    while (true) {
        double time=System.currentTimeMillis()+200;
        double currentTime=System.currentTimeMillis();
        double offset=0;
        int tries=0;
        double maximo=0;
        double minimo=0;
        while(time>currentTime){ //lets run for 0.2seconds :)

            try {
                double temp=-accel.getAccelY(); //front shouln't be negative
                tries++;
                if(temp<0.1201 && temp>-0.1201){
                    tries--; //oops threadshould sample
                }else{
                    if(temp>maximo)
                        maximo=temp;
                    if(temp<minimo)
                        minimo=temp;
                    offset+=temp;
                }   
            }catch (Exception e) {
                System.err.println("Caught " + e + " while collecting/sending sensor samples.");
            }
            Utils.sleep(10); //sleep 10milisecs
            currentTime=System.currentTimeMillis();
        }
        if(tries>2)
            offset=(offset-minimo-maximo)/(tries-2); //remove max value and min value from sample and makes average
        else if(tries>0)
            offset/=2; //you wont take max or min from a two value sample
        try {
            dg.reset();         //clears
            v=anterior+offset*0.2; //vf=vi+at
            dg.writeDouble(Math.abs(v*100)); // sends in cm
            anterior=offset;    //vi=vf
            rCon.send(dg);     //sends radiogram
            Utils.sleep(200); //sleep 0.2s
        }catch (Exception e) {
            System.err.println("Caught " + e + " while sending velocity.");
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多