Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Help! Programming question with triggers (http://www.chiefdelphi.com/forums/showthread.php?t=26863)

AsimC 17-03-2004 17:48

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: )

bstempi 17-03-2004 18:21

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?

JoshJ 17-03-2004 18:27

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.

KenWittlief 17-03-2004 18:27

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

Astronouth7303 17-03-2004 18:47

Re: Help! Programming question with triggers
 
Quote:

Originally Posted by KenWittlief
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

If you have a victor, try this:
Code:

pwm01=p1_sw_trig*127+127;

Ryan M. 17-03-2004 18:48

Re: Help! Programming question with triggers
 
If they are on PWMs, do something like:
Code:

if(switch == 1){
    pwm01 = pwm02 = 254;
}
else{
    pwm01 = pwm02 = 127;
}

Where pwm is the motor(s) and switch is the switch.

Xufer 17-03-2004 19:26

Re: Help! Programming question with triggers
 
i did mine like this
Code:

pwm03 = 127;  /*goal claw up and down*/
if (p2_sw_top)
{pwm03 = 195;}  /*half speed down*/
else if (p2_sw_trig)
{pwm03 = 59;} /*half speed up*/


AsimC 17-03-2004 20:21

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)
{
  pwm07=175;
  pwm08=175;
}
if (p3_sw_top==1)
{
  pwm07=90;
  pwm08=90;
}


Mr. Lim 17-03-2004 20:26

Re: Help! Programming question with triggers
 
Code:

if (p3_sw_trig==1)
{
  pwm07=175;
  pwm08=175;
}
else if (p3_sw_top==1)
{
  pwm07=90;
  pwm08=90;
}
else
{
  pwm07=127;
  pwm08=127;
}

try this... just beware if you push both the trigger and top button at the same time, it'll still go forward.

AsimC 17-03-2004 20:35

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.

WebWader125 17-03-2004 20:44

Re: Help! Programming question with triggers
 
Quote:

Originally Posted by AsimC
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.

Did you try something like that, or did you try exactly what Slimbo posted? If you had two IF's but only one ELSE, it would probably behave how you've described.

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?

doy 17-03-2004 20:44

Re: Help! Programming question with triggers
 
Quote:

Originally Posted by AsimC
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.

if at the rest state of the switch, both outputs are 0, then his code should work... if not, then i dont think the switch will work for what you want it to do, as there would be no way to tell whether or not the switch was being pushed in a direction or at rest.

AsimC 17-03-2004 20:50

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.

The Lucas 17-03-2004 21:09

Re: Help! Programming question with triggers
 
Quote:

Originally Posted by AsimC
when i pull the toggle switch back...the motors do run in reverse...but again they do not stop even when i let go.

Do your motors run at startup?

Greg 17-03-2004 21:17

Re: Help! Programming question with triggers
 
Quote:

Originally Posted by AsimC
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.

Then its your switch. Just because it returns to center does not mean the switch is opened :)


All times are GMT -5. The time now is 12:01.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi