AVCampos Posted October 7, 2013 Posted October 7, 2013 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! Quote
Conchas Posted October 7, 2013 Posted October 7, 2013 If I could suggest anything, I'd recommend you to raise this question at the MindBoards Forums, where you may get the support from the most prominent specialists in the field and even the authors of NXC. Quote
Carsten Svendsen Posted October 8, 2013 Posted October 8, 2013 (edited) Couldn't you just use an "IF" command instead? Like: if motorlimit = true; motor = 0; else; motor = 100; end_if; Edited October 8, 2013 by Carsten Svendsen Quote
AVCampos Posted October 8, 2013 Author Posted October 8, 2013 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". Quote
Jim Posted October 8, 2013 Posted October 8, 2013 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. Quote
Carsten Svendsen Posted October 8, 2013 Posted October 8, 2013 It was just an example for the simple and very basic "IF" command You'd have to replace the condition for if to be true or false depending on the way you program it Quote
Jim Posted October 8, 2013 Posted October 8, 2013 That's what he is doing, but the MotorOverload always returns false. Quote
AVCampos Posted October 8, 2013 Author Posted October 8, 2013 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. Quote
Carsten Svendsen Posted October 8, 2013 Posted October 8, 2013 Oh ok, sorry for the inconvenience Quote
Jim Posted October 8, 2013 Posted October 8, 2013 Oh ok, sorry for the inconvenience No problem. You were just trying to help Quote
AVCampos Posted October 8, 2013 Author Posted October 8, 2013 Of course! Even if a reply isn't a solution, it may lead to a solution or inspire a solution. Quote
kieran Posted October 8, 2013 Posted October 8, 2013 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. Quote
Jim Posted October 8, 2013 Posted October 8, 2013 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? Quote
AVCampos Posted October 9, 2013 Author Posted October 9, 2013 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. ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.