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 21:18

Re: Help! Programming question with triggers
 
startup meaning when i turn the robot on?.... nope they dont move

The Lucas 17-03-2004 21:22

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]

AsimC 17-03-2004 21:28

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

The Lucas 17-03-2004 21:33

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.

KenWittlief 17-03-2004 22:16

Re: Help! Programming question with triggers
 
Quote:

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



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

Xufer 17-03-2004 22:48

Re: Help! Programming question with triggers
 
try this its the code i use to run my claw modified for your application
Code:

pwm07=127;
pwm08=127;

if (p3_sw_top)
{ pwm07 = 90;
  pwm08 = 90; }

else if (p3_sw_trig)
{ pwm07 = 175;
  pwm08 = 175;}


adventrx327 17-03-2004 23:00

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

Joe Ross 17-03-2004 23:07

Re: Help! Programming question with triggers
 
Quote:

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

Here is the reason: http://www.chiefdelphi.com/forums/sh...34&postcount=3 However, in the future don't be afraid to ask your mentor to explain things like that you don't understand.

Anthony Kesich 17-03-2004 23:20

Re: Help! Programming question with triggers
 
Code:

pwm07 = pwm08 = 127 + ((p3_sw_trig - p3_sw_top) * 40);
One line. I found it very useful this year. You can changew the numher at the end (40) to whatever scale you want. trig will make it go forward, top will make it go back, and either both or none will make it just sit there.

-Kesich

adventrx327 18-03-2004 00:30

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.

KenWittlief 18-03-2004 07:01

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.

The Lucas 18-03-2004 11:00

Re: Help! Programming question with triggers
 
Quote:

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

Actually both routines, Anthony Kesich's one-liner and Xufer's selection structure, take exactly 22 bytes of program space, just check the list file (FrcCode.lst) after compiling both. Xufers routine was the most program space efficient of the selection structures I saw because it involved the least branching (i.e. no else to set neutral which only takes 2 bytes). Anthony’s routine could probably be optimized in assembler since only the sign bit and least significant bit of one of the factors is relevant (I don't program in assembler so I am not sure). One-liners are much better for relays because it is simply addition no multiplication.

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