![]() |
Help! Programming question with triggers
its the day before competition and i really need help on this. Our team decided to make a trigger box for our robot and one trigger controls 2 motors. What i what it to do is, when i hold the trigger forward, the motors go forward, and when i let go the motor stops. For some reason i cant get it to work. What happens is, i hold the trigger forward and the motors continuely move even if i let go. Ive tried IF loops as well as FOR loops. Any suggestions? (as quickly as possible :ahh: )
|
Re: Help! Programming question with triggers
how do you have it wired up? From what you posted, it sounds like some sort of toggle switch you're using. Do you know what variables that coresponds to in the code?
|
Re: Help! Programming question with triggers
See if u can post a copy of your code. I would stay away from FOR loops, all u should need to do is set the motors to something when ur trigger is forward, and set them to 127 when it is not. Also, see if you have any other code that assigns values to these motors.
|
Re: Help! Programming question with triggers
you dont need an if statement
just something like relay_fwd01 = p1_trig01; in your code when the switch is on the relay is on, when its off, the relay goes off |
Re: Help! Programming question with triggers
Quote:
Code:
pwm01=p1_sw_trig*127+127; |
Re: Help! Programming question with triggers
If they are on PWMs, do something like:
Code:
if(switch == 1){ |
Re: Help! Programming question with triggers
i did mine like this
Code:
pwm03 = 127; /*goal claw up and down*/ |
Re: Help! Programming question with triggers
hmm this is how i originally did it...but it doesnt work. What happens is when i click the trigger, its constantly going forward even when i let go.
Code:
if (p3_sw_trig==1) |
Re: Help! Programming question with triggers
Code:
if (p3_sw_trig==1) |
Re: Help! Programming question with triggers
i forgot to say...it is a self centering toggle switch. Toggle forward is wired up to "trigger", and toggle back is wired up to "top" in code.
Anyways... Slimbojones when i was debugging my code, i tried something like that... and it didnt work. What happens is the 1 from p3_sw_trig is held in the code, so it never goes back to 0 and that means itll never go to neutral. |
Re: Help! Programming question with triggers
Quote:
One question I have: What happens when you push the toggle switch down? Do your motors actually run in reverse then? Or is forward the only direction that's working at all for you? |
Re: Help! Programming question with triggers
Quote:
|
Re: Help! Programming question with triggers
when i pull the toggle switch back...the motors do run in reverse...but again they do not stop even when i let go.
|
Re: Help! Programming question with triggers
Quote:
|
Re: Help! Programming question with triggers
Quote:
|
Re: Help! Programming question with triggers
startup meaning when i turn the robot on?.... nope they dont move
|
Re: Help! Programming question with triggers
if you push it in reverse and let go does it keep going in reverse? or go forward?
[EDIT] I also think it is a switch wiring problem [/EDIT] |
Re: Help! Programming question with triggers
the thing is that....the SAME EXACT thing happens when i hooked up a joystick to it...so i doubt its an electrical problem.
*EDIT - using the triggers from a joystick |
Re: Help! Programming question with triggers
Could you post the file then? The algorithms on this thread are good so the problem is somewhere else. I am sure with all the CD programmers someone will find it real quick.
|
Re: Help! Programming question with triggers
Quote:
the reason why your motors keep running is because there is no path in your code where you tell them to be = 127 and stop running the way your code is written if neither switch is closed then the pwm outputs will still be what they were the last time the loop ran, and the time before that... your code leaves them at 175 or 90. you could put pwm07=127; pwm08=127; above your if statement - have them = 127 by default, then if either switch is closed they will be something else instead this is a common mistake |
Re: Help! Programming question with triggers
try this its the code i use to run my claw modified for your application
Code:
pwm07=127; |
Re: Help! Programming question with triggers
Here is how i would write it if i were you guys....
if ( 0 != p3_sw_trig) { pwm07 = 175; pwm08 = 175; } else if (0 != p3_sw_top) { pwm07 = 90; pwm08 = 90; } else { pwm07 = 127; pwm08 = 127; } When writing my code i didnt do p3_sw_top == 1, my mentor sez its better to do 0 !=, and i have no idea why. try this, if it works yay! if not sorry i couldnt be of more help |
Re: Help! Programming question with triggers
Quote:
|
Re: Help! Programming question with triggers
Code:
pwm07 = pwm08 = 127 + ((p3_sw_trig - p3_sw_top) * 40);-Kesich |
Re: Help! Programming question with triggers
Oh my god!
So concise, so effective, so 1337! I salute you Anthony, you truly embody the spirit of first. |
Re: Help! Programming question with triggers
it is concise in C - but unless the CPU has a HW multiplyer then multiplyer that one line of code might compile into something that will take hundreds of machine cycles to execute in assembler
when you only need an '=' getting clever to make your C look concise is usually a big mistake. |
Re: Help! Programming question with triggers
Quote:
Processor speed is a different story and depends on the processor architecture. |
| All times are GMT -5. The time now is 22:47. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi