Trying to assess the rough position of the system, and take action if the position is beyond a given value. Doing something like this (simplified)
Code: Select all
int speed = 50;
set_velocity(MOTOR, speed); // Acceleration is 100
while (get_hall_value() < 700) { // CPhidgetInterfaceKit_getSensorValue()
usleep(1000); // 1 ms
}
speed = -speed; // Reverse speed
set_velocity(MOTOR, speed);
...
When it does, it reverses the speed and go back a few centimeters (then stop).
This works fine as long as the speed is <= 50.
Above 50 (intended speed is above 80 actually), there is a delay between the position detection (hall value >= 700) and the reaction (reverse speed). Meaning the robot goes a few centimeters farther than expected (No inertia issue, since for the prototype we use very light devices).
• Checked manually, reversing speed is visually instant
• Did Hall sensor tests in another program: here again the position detection is visually instant (ie the value returned by the CPhidgetInterfaceKit_getSensorValue() function has no delay, even when called thousands of times a second)
So I wonder why the delay occurs:
• Is mixing two Phidgets USB devices in the same program add some delay (threading Hall processing would help?)
• Is polling the Hall sensor USB so many times (every ms) gives a buffering/delay? Meaning the polling is asynchronous?
• In this case what would be a solution to this problem?
Thank you