简体   繁体   English

如何计算太阳点的方向/方向和速度?

[英]How do i calculate the orientation/direction and the velocity of a Sun Spot?

I am experimenting with the accelerometer on my sunspot. 我正在尝试使用黑子上的加速度计。 I am trying to calculate the velocity by measuring the values of the accelerometer from the axis X and Y but they kind of seem random to me. 我试图通过从X轴和Y轴测量加速度计的值来计算速度,但是它们对我来说似乎是随机的。

What's the proper way to get the values and the orientation/direction of the movement and to calculate its velocity? 获取运动的值和方向/方向并计算运动速度的正确方法是什么?

This is my code: 这是我的代码:

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
          }}...

UPDATE For example, I move the sunspot in a direction and the variable v(velocity) give me values from negative up to 7ms by random order (not sequencial). 更新例如,我沿某个方向移动黑子,变量v(velocity)给我的值从负数到7ms的顺序是随机的(不是连续的)。 If the change the direction of the movement it doesn't give me negative values as I expected. 如果改变运动方向,则不会像预期的那样给我带来负值。

example:(if I move it to my right) 示例:(如果我将其移至右侧)

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

Thanks in advance. 提前致谢。

Like @John Story stated the best way to handle this is by making an average. 就像@John Story所说的那样,处理此问题的最佳方法是求平均值。 Sun spots accelarometers are very unstable and aren't suited for precise velocity prevision. 太阳光斑加速度计非常不稳定,不适合精确的速度预设。

Anyway this is the best code i could make 无论如何,这是我能做的最好的代码

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.");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM