always the first function to test when mouse is constructed

I got my mouse constructed recently, everything were fine except the external crystal wasn’t oscillating, so I used internal crystal instead.

IMG_0902_resize IMG_0907_resize IMG_0917_resize IMG_0922_resize

There is always an first function you want to test on your mouse after all devices are properly settled. My favorite function is the one that makes mouse keep distance with wall by using 2 front sensors, also it’s the easiest function for me to write. Here is the code for this function:

void adjuster(void)
{
int curt = micros();//start to track time in order to make one adjust every 1000us
readSensor();
setLeftPwm((2900- LFSensor));//set left motor speed
setRightPwm((2500 – RFSensor));//set right motor speed
TIM2->CNT=25000;//keep resetting encoder counts prevent overflow
TIM3->CNT=25000;
elapseMicros(1000, curt);//elapse 1000 micro seconds
}

I also took a video to DEMO this function:

once you have this function working, PID is usually the next to test since we will be able to write a similar function to make mouse stop if there is a wall to the front when mouse is moving forward with PID. I will talk about how to write a simple PID by utlizing 2 side sensors next time.

2 thoughts on “always the first function to test when mouse is constructed

  1. Nice blog post! Pretty simple code, but impressive test run in video:) I can’t wait for your PID code.
    P.S: What’s the capacity of lipo (mAh)?
    P.S: Why did you wrote 2900 value for one motor and 2500 for another? Your both motors doesn’t have same speed? I thought that, faulhaber motors are perfect 😉

  2. my batteries are 110mah sparkfun battery, but I think the discharge rate isn’t that high, I might parallel 2 batteries to make higher discharge rate.
    2900 and 2500 are the IR sensor distance threshold for left front sensor and right front sensor. Their reading are different since I was too lazy to adjust them at beginning 🙂

Leave a Reply to Kamil Karczmarczyk Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.