Hello all,
I have just incorporated the Cam 2,3 turret on my robot. - Over the past few days, I've been experimenting with gathering data using sensors on the turret. So far, I'm not satisfied with what I have coded. I was wondering if anyone had a pattern for gathering data, moving the turret gathering more data, etc...I am using the Serializer and C# (not MSRS).
My problem has been delaying the main thread (for the turret to actually get to its spot (let's say 5 or 10 ticks), then taking an accurate measurement. I have tried to block other threads to no avail and manually triggering "pumpEvents()" directly after the turret moves. I'm sure I'm missing something very simple.
As I mentioned above, if anyone has a successful pattern to do this, I would really appreciate it.
Thank you in advance,
Joe
Take a look this snippet for a general feel for what I am doing:
{
pan(i);
MotherBoard.PumpEvents();
rawReadings.Add(Front_IR_Sensor);
}
Joe,
Since you want to pan to a desired position, take a reading, record it, and continue on, I think I would suggest using the Update() method on your IR sensors, then read the distance property, instead of relying on the periodic polling, and event firing built into the .NET lib. You could try something like this:
int panPos = 0;
bool panningRight = true;
while (true)
Pan(panPos);
FrontIR.Update(); // Request reading, and block until the Distance property has been updated w/ latest reading
RawReadings.Add(panPos, FrontIR.Distance); // Store latest reading, based on
Thread.Sleep(40); // The IR Sensors aren't faster than about 40msec, so sleep at least that long
if (panningRight)
if (panPos < 100)
panPos++;
else
panningRight = false;
if (panPos > -99)
panPos--;
panningRight = true;