If you've seen any of my previous posts, I have 2 robots that have the same objectives. One is on tracks and the other is a Bi Ped walking robot. I've had them both for about 3 years and continuously make them both more accurate, advanced and efficient. They typically leapfrog past each other in efficiency and tasks untill I get the other to catch up.
The Bi Ped robot in question has 6 servos for movement and one servo for panning. The pan servo has a camera to look for certain colors and an IR distance sensor to avoid objects. The robot is very accurate and does what it is supposed to. But I'm looking to make it better. Currently the panning servo only pans in between steps, not while the robot is walking. I'm trying to make it so the pan servo will pan continuously while the robot is walking and scanning for objects. I'm afraid that the Walk() is a blocking function that is not allowing the pan servo to pan while the robot is walking. Below is my current code for the appropriate loops.
int scanIncrement = (RCS_MAX_POS - RCS_MIN_POS) / 150;
uint32_t lastMove = 0;
void ScanForBlocks()
{
if (millis() - lastMove > 8)
{
lastMove = millis();
panLoop.m_pos += scanIncrement;
if ((panLoop.m_pos >= RCS_MAX_POS) || (panLoop.m_pos <= RCS_MIN_POS))
{
tiltLoop.m_pos = random(RCS_MAX_POS * 0.6, RCS_MAX_POS);
scanIncrement = -scanIncrement;
if (scanIncrement != 0)
{
Walk(15);
Walk(15);
}
}
pixy.setServos(panLoop.m_pos, tiltLoop.m_pos);
}
}
Above you can see that once the servo pans to either side the robot takes 2 steps then will scan again.
Here is the loop. All of these functions work as expected.
void loop()
{
read_Ir();
ScanForBlocks();
camera();
if ((ir > Middle) && (millis() - lastBlockTime < 500))
{
Walk(5);
r2D2();
{
while ((ir > Middle) && (millis() - lastBlockTime < 600000))
{
Rest();
read_Ir();
}
}
}
else if ((panLoop.m_pos < RCS_CENTER_POS) && ir > Far && (millis() - lastBlockTime > 500))
{
laugh();
Turn_Right(200);
}
else if ((panLoop.m_pos > RCS_CENTER_POS) && ir > Far && (millis() - lastBlockTime > 500))
{
laugh();
Turn_Left(200);
}
}
Next I'll post what I've tried and the results.