Calibration Strategy Part 2


In this post, I am going to talk about how to use side sensors or diagonal sensors to correct longitude position by detecting wall-to-no-wall transition or post-to-post-transition.

Other than using front sensors to correct longitudinal when front wall is available, using side or diagonal sensors to detect the opening of side walls when going straight is also extremely useful to minimized the chance the crash during the search and speed run.

This strategy is always being used whenever the side/diagonal sensor(for my mouse I use diagonal sensor most of the times, so I will use diagonal sensor only to explain the theorem through the entire post) see a opening transitioning from a wall or a single post. In this case, the mouse will be able to recognize its longitudinal position and keep itself on track especially running at a long straight away.

only post

Before I start to make it work, we need to get some data for diagonal sensor in order to observe what will the sensor value look like.

Since the infared light that the LED diode sending out has a cone shape with about 10 degree angle(SFH4545 has 10 degree full angle, SFH4511 has 6 degree full angle, just FYI), so the effective reflecting areas are definitely different between a full wall and a single post since the surface for a post is significantly smaller than a wall(obviously :) ) wall   no   wal

Thus, the expected max sensor reading reflected from a post should be smaller than reflecting from a wall. In order to prove this, I made my mouse record the right diagonal sensor value every one millisecond when the mouse was moving forward for one cell by starting and ending at the spot mentioned in the picture as follow:

move diagram

I did this twice, first time was to gather the data when there was no right wall, and one post can be detected during the process. The second time I pretty much repeat the same procedure except a wall was added to right side for mouse in order to compare the difference between two cases.

wall - Copy

The mouse was running at exactly same speed and start at same place, running for exactly same distance. After I did these 2 trials above, a sketch had been formed based on the data logged out from my mouse through the Bluetooth adapter add-on. wall-no-wall transition

As you can see above, there are 2 curves when different colors represent the sensor readings through the process when the mouse was moving forward for one cell. The red one is the reading for my first trial, which was the case there was only post exist, and the blue curve is the case with wall to the right side. Same as what I expected, the maximum reading for the case with wall is much higher than the case without wall(with only post). wall-no-wall transition - Copy

The similarity we can spot on the diagram above is the sensor readings were remaining at high values for some certain amount of time before gradually fading off. The area where the sensor readings were fading off is where the mouse detect the exiting edge of a wall or a post. This is what I called wall-to-no-wall or post-to-no-post transition at the beginning of this post.only post - Copy

As long as what the sensor will behave, the logic becomes very simple to allocate when this transitioning process is going to happen. Here is some sample code for detect this process for right wall only(1ms interrupt is not used in this case, it will be same process for left wall detection):

void moveForwardOneCell(void)
    hasRightWall = false;
        int curt = micros();
        if(rightDiagonalSensor > hasWallSensorValue)
            hasRightWall = true;
        if(rightDiagonalSensor < rightSideFadingOffValue &&  hasRightWall = true)
             hasRightWall = false;
             distance = someNewValue;

        while((micros()-curt)<1000);//keep 1ms sample time

just notice hasWallSensorValue and rightSideFadingOffValue can either be same value or the “rightSideFadingOffValue” be smaller than “hasWallSensorValue”. The reason I made one smaller to another is to prevent the transition process being mistaken detected multiply times when the mouse only passed by a single post or wall. wall-no-wall transition - Copy (2)

After all the explanations I made above, you will be able to understand how it works in the video demo I show below:


Because of “rightSideFadingOffValue” is detected at different place for wall-to-no-wall and post-to-no-past cases, the ending longitudinal position for mouse will be slightly different.

wall-no-wall transition - Copy - Copy

For my case, the different is only 4mm, it might be good enough if your mouse is running stable enough, however this quite critical for diagonal run since lots of times mouse are running “blindly” with less chance to do calibration compare to search run. Therefore, the 4mm different here is not tolerable. The way I dealt with it was just made 2 different cases when side wall is there or not. This is just a easy fix for me since the side wall information is usually known already before my mouse made decision for next movement action.

Other than the case above, This strategy can also be used at some other place for longitudinal calibration purpose.

One usage is for longitudinal correction in the diagonal straight away. Please see the picture as follow:

diagonal post

the other usage is to make a detection as the last chance for the mouse to correct longitudinal position before a turn in the diagonal run since all turns start earlier than the turns in search run. Therefore, front sensor values are too weak to help the mouse to correct its position before turn since front wall is way farther than the front wall in search run. search turn spot_resize

Please be aware that this strategy will only be accurate if and only if the mouse remains in the middle of the cell, otherwise, more special tectonics are needed. I might talk about this in the future.

The content preparation took me longer than I expected since I was trying to make everything being explained super clear(however I don’t think I make it here :(  )  I hope you will be able to utilized this helpful strategy to make your mouse run smoothly and stably in the maze after you read this!