![]() |
Code for sensor still doesn't work
Hey, sorry about making a billion threads about this, but I'm trying to get your attention as quickly as possible since we don't have much time left. the code for my sensor does not work properly and I don't know where the problem(s) is(are). It is a metal detector that will sense a metal strip in a rope that is used in a winch system to lift the ringers. The metal strips will be placed in certain locations so that when the rope/metal strip passes the metal detector the motor will stop. If i want to keep going I simply press the trigger and it goes to the next level of the SPIDER. This is the code. Any help would be fantastic. If you have questions, please ask them so I can help you help me! THANKS!
In User_Routines.c: Code:
void Default_Routine(void)CODE THAT RELATES TO SENSOR/FORKLIFT Code:
if((now3 == 1) && (last3 == 0)) //p3_sw_aux1 sets counter to 0 in case forklift needs to be reset. |
Re: Code for sensor still doesn't work
Quote:
That evaluates to "is pwm03 not equal to p3_y". The answer is ignored, so the statement has no effect. What do you mean for it to do? --buddy |
Re: Code for sensor still doesn't work
Ianuser,
While I haven't really taken a detailed look at your code, I believe you want to make all your now/last variables static (static int now; ). As they are written, they will lose their value when the Default_Routine exits as they are only temporary stack variables. Mike |
Re: Code for sensor still doesn't work
I think that you think the code is constantly making sure that pwm03 is equal to p3_y. In reality, it only does this once, at the beginning of your code,
Code:
if((now2 == 1) && (last2 == 0)) //p3_sw_trig sets joystick 3 y-axis to forklift motor. Use after each level.What I think you mean by the pwm03 != p3_y statements is "I don't want pwm03 to equal p3_y anymore. Instead, I want it to be 127." In C (in fact in most programming languages) this is completely unnecessary. All you have to do is say pwm03 = 127; and it will overwrite the previous value. However, I don't think this is the problem with your code. My guess is this..... That switch only triggers for a minute fraction of a second, when the tape passes in front of it. The only way your code will work is if at the exact moment that the switch triggers (when rc_dig_in04 is 1), your program has to be executing the exact line of code that assigns rc_dig_in04 to another variable. If this is not the case, which it won't be 99% of the time, rc_dig_in will be 0, and your other variable will be zero, even if the sensor detected the metal tape. What you need to do is trigger an interrupt when the sensor triggers. What this will do, is when the sensor triggers, it will stop all your other code, and go straight to the interrupt handler (which can be found in user_routines.c) and execute that code, while the sensor is still triggered. You can add your own code to the interrupt handler and it is there that you can set another variable to 1, saying that the sensor has triggered, and handle the stopping of the motor and all that, elsewhere (where it is now is fine). Edit: Yes, static variables are also necessary. Remember, this code is not executing constantly, it is executing many times each second. Which means that Default_Routine() is being called and returning many times per second. Each time it does, all your now and last variables are being reset to zero. |
| All times are GMT -5. The time now is 13:56. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi