Jump to content

Recommended Posts

Posted

Hi all!

I'm programming a robot that has limited travel on one of its articulations. I don't require precision on its position, just that it stops the motor as soon as it hits the limit.

NXC has the MotorOverLoad function, which appears to do exactly what I want... however, it always returns "false" even if the motor is completely stalled! Digging a bit, I found that MotorOverload is actually a shortcut for one of the fields of GetOutput (like "GetOutput(OUT_A, OverloadField)"). Checking the field's documentation, I see that, for it to work, I need to set the motor according to numerous parametres... but, after setting them, I can't get the motor to actually run!

This is what I wrote to get the motor running, while enabling MotorOverload:

SetOutput(
 OUT_C,
 RunStateField, OUT_RUNSTATE_RUNNING,
 OutputModeField, OUT_MODE_MOTORON + OUT_MODE_REGULATED,
 RegModeField, OUT_REGMODE_SPEED,
 PowerField, power_C * d);

(power_C and d are variables I defined)

If I use the normal "OnFwd" instead, the motor is never stopped:

if(MotorOverload(OUT_C))
{
 Stop(OUT_C);
}

What could I be doing wrong? Thanks in advance!

Posted

What language did you use for that code? It doesn't have the structure of NXC, and I couldn't find any NXC function named "motorlimit".

I think he is using pseudo code, not an actual language.

But you are using an If statement, so I am not sure what he means either.

Posted

Yes, that's what I'm doing. The problem is that, if I use the first piece of code instead of the normal "OnFwd", the motor doesn't start... if I do use "OnFwd" and the second piece of code, the motor doesn't stop.

Anyway, I followed Conchas' suggestion and posted the question at Mindboards.

Posted

the trick to this is to monitor the rotation count of the output in a timed interval, if the rotation count is zero or a very low number you know the outpout is not rotating, i.e. its stalled.

Posted

the trick to this is to monitor the rotation count of the output in a timed interval, if the rotation count is zero or a very low number you know the outpout is not rotating, i.e. its stalled.

Indeed. But shouldn't the MotorOverload method do this for you?

Posted

I got the solution! My problem was that I was missing the update flags on SetOutput, which commit the changes. By using OnFwdReg, all required parametres were set automatically. Here is John Hansen's explanation.

Anyway, I found out by experimentation that MotorOverload takes a while to conclude that the motor is stalled (it increases the motor power to try to overcome the limit until it gives up), so I checked instead if MotorActualSpeed (the power applied to the motor) was greater than 75%, and it worked.

if(abs(MotorActualSpeed(OUT_C)) > 75)
{
Off(OUT_C);
stall_C = sign(MotorActualSpeed(OUT_C)); //Won't try moving in this direction next time
}

kieran, there's no need to manually do that: that's (if I'm not mistaken) the purpose of the MotorTurnRatio function. ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...