2012年5月13日日曜日

Velocity measurement with the Kojimouse7 encoder

I received a youtube message from a mouser about the encoder of Kojimouse7. I want to answer the question in this blog so that we share the technique to estimate velocity of a mouse with other mousers.

Kojimouse7 has two sets of a spur gear with 8 holes and a photo reflector. The processor counts the edges of the holes while the wheel is rotating in order to measure the speed of the wheel. It can detect 2 edges for a hole, so, the resolution of this encoder is 16 per revolution. Since my mouse is controlled based on the 1 milisecond periodic interrupt, that low resolution encoder doesn't give enough precision for the instantaneous velocity.

It is almost impossible for a mouse to run smoothly only with the encoder. However, 100 ms average gives a comparatively precise velocity. In this case, the problem is that the obtained velocity is past information, which is a velocity of the mouse approximately 50 ms before.

In order to compensate the delay, Kojimouse7 uses acceleration sensor. Although an acceleration sensor is not good at measuring precise velocity in the long time scale due to the accumulation of errors with time, the integral of the acceleration in very short period gives the velocity change with good precision. So, accelerometer is very useful to compensate the velocity obtained using the encoder, which is past information. The instantaneous and latest velocity of a mouse is roughly obtained by adding the average of the encoder and the velocity change measured by accelerometer.

In short, Kojimouse7 measures the velocity by means of combining the average velocity obtained by the low resolution encoder and the velocity change measured by the acceleration sensor.

I hope you (readers of this article) understand the method above. Further questions and comments are welcome.

21 件のコメント:

Augusto さんのコメント...

i have 256 pulse per revolution that gives me an accuracy of almost 0,3 mm.how do you reccomend to mesaure instantaneous velocity?The interrupt is called like in your mouse every 1ms.
Thank you very much
Augusto.

kojima さんのコメント...

> Augusto
Thank you for your comment.

The resolution of 0.3mm/pulse means that the resolution of velocity is 300mm/s in the case of 1ms interrupt interval.
This is too low to control the mouse.

If I use the encoder, I would store the last five, ten or more velocity data measured in every interrupt, and use average of these data as a instantaneous velocity, though it requires some memory and calculation time.

Augusto さんのコメント...

just to be safe would you reccomend to use an accelerometer or a gyro to measure the rotational velocity? Also is better to place the device beetwen the wheel or it can be positioned everywhere i want ?

kojima さんのコメント...

I think you mean rotational velocity is angular velocity of a robot not a wheel. If so, an accelerometer is not suitable. Gyro is a very good device to measure angular velocity. Although you can measure it using left wheel speed and right wheel speed, gyro gives more precise result when the speed of mouse is very high.

Also, gyro can be located everywhere you want.

mog123 さんのコメント...

I have a question regarding combining the inputs, are you using a Kalman filter or something of your own design?

kojima さんのコメント...

Velocity v of the mouse is roughly calculated as follows in my mouse,
v = [the average of encoders in the last 100ms] + [the integral of the accelerometer in the last 50ms]

Filters are not used, but "average" and "integral" work as a filter.

축구사랑 さんのコメント...

Hello I'm starter on micromouse. Thank you for your information.
How to integral last 50ms data? Do you get some function of last 50ms data?

Kojima さんのコメント...

Data obtained every 1ms from the accelerometer is stored in RAM. The integral simply means [the sum of them] times [sampling interval] (1ms here). To store the some latest data, a ring buffer is used.

축구사랑 さんのコメント...

Thank you to answer. I have more questions.
1)Why don't you use trapeziums calculation?

2)In your comments
v = [the average of encoders in the last 100ms] + [the integral of the accelerometer in the last 50ms]
why did you add two data? I think first data is velocity and second data is velocity too. It means [velocity]+[velocity]. Why...?

3)After we get the mouse velocity by above equaion. When we use that? For example when stop mouse? when turn mouse?

Thank you to reading.

Kojima さんのコメント...

1) To reduce calculation cost. Trapezium calculation will slightly improve the accuracy.

2) The first data [the average of encoders in the last 100ms] has temporal delay, so the change of velocity in short term is added to compensate the delay. If you have high resolution encoders, the average size can be reduced and the second data addition is not required.

3) The equation is always used including straight and turn. The equation is basic dead-reckoning method for my mouse.

Further questions are welcome.

축구사랑 さんのコメント...

thank you. I think I understand about 50%.
As I understand [v=v0+at] so if we add two data above, we can get instaneous velocity more precise. Is it right?

more questions.
1)Why the velocity of last 100ms average is equal to last 50ms before?Why not equal to 100ms before?

Thank you for spending your time for me.

Kojima さんのコメント...

I think you understand what I mean. Precise velocity can be obtained by adding the two data.

When present velocity is 'v' and acceleration is 'a' (which is assumed to be constant), velocity 100 ms before is [v - a*100]. So, the average velocity in this 100 ms is [(v + (v-a*100))/2] = [v - a*50], which is velocity of 50ms before.

축구사랑 さんのコメント...

Thank you! I understand about 90%. [v-a*100] was the key. I will complete remain 10% by making mouse really.

I will try to make mouse referenced by your Kojimouse7. Because I think there are many point to learn in your mouse. Thank you again for sharing your valuable information.

May I ask to more questions?
1)In your schematic , you use just 1 photo reflector each wheel
And then how to check wheel direction?

2)Some FET(RUM003N02) connected to cathode of photo reflector.
Why use that? Do you control photo emitter by some pulses?
I think it does not matter the emitter work continuously......

3)How to mount your motor to PCB? Did you use some loctite? or tape? I could not find the method in your photo

Thank you for reading.

Kojima さんのコメント...

1) Wheel rotation direction cannot be detected. So, only accelerometer is used in very slow motion. In normal run velocity, the direction is the same as that of PWM duty.

2) I think continuous light will also work well. However, because battery capacity is only 50mAh in this mouse, a few tens of mA current consumption is too high. So, pulse operation is used to reduce battery consumption.

3) Double sided tape is used. And, in order to adjust the clearance between gears, one or two pieces of paper are inserted as a shim between a wheel mount (Black POM in the photo) and a motor. But, anyway, tape cannot completely fix the motor. This may not be a good way.

축구사랑 さんのコメント...

Thank you Kojima.
I wondering now about mechanical structure of Kojimouse7

1)How to mount spur shaft to PCB?
Did you make mounting jig yourself? or buy it? include spur shaft

2) How to connect tire to spur? It seems like bonded each other. Is it right?

I'm sorry to keep asking. Thank You.

Kojima さんのコメント...

1) The shaft is held by ball bearing and bearing is mounted on hand-made black POM mount. And the mount is fixed to PCB with a small screw from the back of PCB.

2) This mouse, Kojimouse7, the spur (http://indoor-airplane-world.com/?pid=8635098) is inserted into the wheel (pinion part is inserted). In my newer mouse, spur is bonded to wheel by slightly melting the plastic with soldering iron.

To explain the structure is a little difficult... I hope you can understand what I mean.

축구사랑 さんのコメント...

Thank you so much. Let me try that.

축구사랑 さんのコメント...

one more question.
Did you make wheel yourself? I can't find suitable wheel to spur(diameter 11.4mm)
Could you inform to me about wheel and tire? model number, etc
Thank you.

Kojima さんのコメント...

I made the wheels by myself with CNC. The tires are Kyosho DNT001-10.
http://www.rt-shop.jp/index.php?main_page=product_info&cPath=1002_1024_1033&products_id=1247&language=en

축구사랑 さんのコメント...

Hello. Mr. Kojima.
Now I draw a schematic reference by your circuit.
If I use QEI(Quadrature Encoder Interface), that is more convient?
I think there is no difference because that we must integrate data to get velocity.
Why you did not use MCU include QEI?

Kojima さんのコメント...

I use A/D converter to obtain the photo-reflector output for handmade encoder because the signal is very small. If the signal is captured by a digital input port of MCU, input will be always 0 (Low). So, high and low is decided by the A/D data by setting some threshold in the software.

If you can get enough output signal level, QEI will be more convenient.

コメントを投稿