Shop OBEX P1 Docs P2 Docs Learn Events
Activity Bot Servo Issue — Parallax Forums

Activity Bot Servo Issue

Hello,

I am new to the Propeller, and this forum. I recently got an Activity Bot and have assembled it. It checks out fine. While trying to learn interaction of the whiskers and servos, I am having a problem! When I run the following code sample, whichever 'if' code block is first it does not work. The whisker fires, the LED is on but there is no servo rotation. So in the sample code below the test for W_Right fires, but no servo movement. If I switch the 'if' code blocks and interrogate W_Left first, I get the same results, it fires, but no servo movement. In both cases, the second 'if' code block works as expected.

Please Help!

Thank you.


while(1) // Endless loop
{
int W_Left = input(7); // Left whisker -> W_Left variable
int W_Right = input(8); // Right whisker -> W_Right variable

if(W_Right == 0) // Right whisker touched!
{
high(27); // LED for left whisker(P27)
//freqout(4, 250, 4300); // Speaker tone: P4, 250 ms, 4.3 kHz
drive_speed(0, -64);
}
else // Right whisker NOT touched!
{
low(27);
drive_speed(0, 0);
}

if(W_Left == 0) // Left whisker touched!
{
high(26); // LED for left whisker(P27)
//freqout(4, 250, 3600); // Speaker tone: P4, 250 ms, 3.6 kHz
drive_speed(-64, 0);
}
else // Left whisker NOT touched!
{
low(26);
drive_speed(0, 0);
}


//print("%c", HOME); // Terminal cursor home (top-left)
//print("W_Left = %d W_Right = %d", W_Left, W_Right);// Display whisker variables

pause(50); // Pause 50 ms before repeat

}

Comments

  • Sorry, forgot, my name is Jay
  • GenetixGenetix Posts: 1,742
    edited 2016-03-06 01:38
    Jay,

    Check your batteries because servos drain them quickly.

    There are 3 possibilities:
    - One whisker was pressed
    - The other whisker was pressed
    - Neither whisker was pressed.

    If you checked both whiskers then the only possibility left is that neither was pressed.
    So, write an if statement like this ===> if (one)...else if (the other)...else // neither must have been pressed

    Refer to this page for that if structure: http://learn.parallax.com/propeller-c-start-simple/make-several-decisions
  • Genetix, Thank you for the help! and the quick answer. I will try the if/elseif block. This is pretty fun stuff! Thank you again.

Sign In or Register to comment.