Go to Post "Hurry, we broke the drivetrain again" - Lil' Lavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2008, 19:47
Lilor Lilor is offline
Registered User
FRC #2595
 
Join Date: Feb 2008
Location: Los Angeles, Ca
Posts: 5
Lilor is an unknown quantity at this point
is it right ???

We are a rookie team and don't have any real programmers. But we have this code, would this hybrid code work? This is what we have:

#define NEUTRAL 127
#define STRAIGHTSPEEDLEFT 215
#define STRAIGHTSPEEDRIGHT 200 //left side not as efficient
#define TURNSPEEDLEFT 54
#define TURNSPEEDRIGHT 200
#define IRswitch1 rc_dig_in01
#define IRswitch2 rc_dig_in02
#define IRswitch3 rc_dig_in03
#define IRswitch4 rc_dig_in04


if (!IRswitch1) //If the IR has been pressed
pwm01-255;
pwm03-255; //Do whatever when switch is down
}

if (!IRswitch2) //If the IR has been pressed
pwm01-127;
pwm03-127; //Do whatever when switch is down
}

Or what are we missing??
  #2   Spotlight this post!  
Unread 12-02-2008, 19:53
psy_wombats's Avatar
psy_wombats psy_wombats is offline
Registered User
AKA: A. King
FRC #0467 (Duct Tape Bandits)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Shrewsbury MA
Posts: 95
psy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura aboutpsy_wombats has a spectacular aura about
Re: is it right ???

That seems about right. Except make sure those lines like pwm01-255; is actually pwm01=255;, otherwise that should be a syntax error. I don't know why the compiler isn't detecting that one.
  #3   Spotlight this post!  
Unread 12-02-2008, 19:59
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: is it right ???

Quote:
Originally Posted by Lilor View Post
Code:
if (!IRswitch1)    //If the IR has been pressed
pwm01-255;
pwm03-255;         //Do whatever when switch is down
}
A few comments:

First, the IR sensor board signals are read as 0 (false) when not active, and as 1 (true) when detecting a signal. That's the opposite of how a switch to ground is typically sensed, so you need to remove the exclamation point.

Second, because of this behavior, a disconnected board will read as if all four signals are active simultaneously. It would be a good idea to put in a check to make sure only one signal is being detected, and ignore everything if multiple signals show up at the same time.

Third, I think you meant to use an equals sign instead of a minus sign. As you have written it, the compiler will accept such lines without complaint, but the code won't actually do anything.

Fourth, you don't have any open braces after your if statements. The compiler will not be happy about that, and will complain about what it thinks is an "extra" closing brace when it encounters one.

Finally, the maximum output for a pwm signal is actually 254, not 255. (I don't know where in the system it gets limited, but I know the dashboard will show 254 if you do attempt to set a pwm output to 255.)
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.o isnt working right... Xenosthebest Programming 2 21-03-2007 00:24
What went right? Cuog General Forum 27 15-03-2007 19:15
yeah right. soezgg General Forum 38 12-02-2003 10:37
IS THIS RIGHT?!?!? RebAl General Forum 22 31-03-2002 00:07


All times are GMT -5. The time now is 00:57.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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