Go to Post 99.9999% of the FIRSTers are really nice - Denman [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 09-02-2004, 22:05
actorindp actorindp is offline
Registered User
#0270
 
Join Date: Jan 2004
Location: Long Island, New York
Posts: 11
actorindp is on a distinguished road
Mapping Buttons to PWMs

Hey guys, how can i map a joystick button to say put pwm08 = 200

Thanks

-Nick
a.k.a
n00b under stress
  #2   Spotlight this post!  
Unread 09-02-2004, 22:08
Ryan Cumings's Avatar
Ryan Cumings Ryan Cumings is offline
Programmer and University Rejected
#0134 (Team Discovery)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Pembroke, NH
Posts: 65
Ryan Cumings is an unknown quantity at this point
Send a message via AIM to Ryan Cumings
Re: Mapping Buttons to PWMs

In a bit of pseudo code

Code:
if(p1_sw_trig) {
   // When we hold down the button do this
   pwm08 = 200;
}
else {
   // When we are not holding down the button, do this
   pwm08 = 127;
}
  #3   Spotlight this post!  
Unread 09-02-2004, 22:09
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Mapping Buttons to PWMs

say you want the trigger to set pwm3 to 200 when pressed, 127 when not:

if(p1_sw_trig) pwm03 = 200;
else pwm03 = 127;

any of the button status variables will work in the if statement.

--edit--
lol, apparently ryan and I are both forum hawks
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #4   Spotlight this post!  
Unread 09-02-2004, 22:25
actorindp actorindp is offline
Registered User
#0270
 
Join Date: Jan 2004
Location: Long Island, New York
Posts: 11
actorindp is on a distinguished road
Re: Mapping Buttons to PWMs

now where do i throw this code?

In default routine?

-Nivk
  #5   Spotlight this post!  
Unread 09-02-2004, 23:03
ShadowKnight's Avatar
ShadowKnight ShadowKnight is offline
Registered User
FRC #1719 (Umbrella Corporation)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2003
Location: Alexandria, VA
Posts: 142
ShadowKnight has a spectacular aura aboutShadowKnight has a spectacular aura about
Re: Mapping Buttons to PWMs

A good majority of the working modifications you make to the default code will go into user_routine.c, but you will want to throw your autonomous code into a specified area of user_routine_fast.c. There actually is a section of the user_routine.c file that is marked with comments indicating that that is where you need to include custom code. Hope that helps.
__________________
Gracious Professionalism isn't simply courtesy or tradition, it's a way of life

I met her through FIRST...

We only are where we are by God's providence and by no other...
  #6   Spotlight this post!  
Unread 09-02-2004, 23:05
FotoPlasma FotoPlasma is offline
\: |
no team
 
Join Date: Jul 2001
Rookie Year: 2001
Location: San Jose
Posts: 1,900
FotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond repute
Send a message via AIM to FotoPlasma
Re: Mapping Buttons to PWMs

Another composition of this if-statement would be:
(p1_sw_trig)?pwm03 = 200:pwm03 = 127;
__________________
I played hacky sack with Andy Baker.

2001-2004: Team 258, The Sea Dawgs
2005: Team 1693, The Robo Lobos
  #7   Spotlight this post!  
Unread 10-02-2004, 00:17
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Mapping Buttons to PWMs

or even (if you want to be fancy)

pwm03 = p1_sw_trig ? 200 : 127;



as a general rule of thumb, if you're working from the default code without massive modifications, anything dealing with user control (such as button mapping) will go in Default_Routine().
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #8   Spotlight this post!  
Unread 10-02-2004, 09:06
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,559
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Mapping Buttons to PWMs

If you want to skip the if statement, you can use the following code

pwm03 = 127 + 63 * p1_sw_trig;

If you want your motor to be able to go backwards also, you can use 2 switches with the following code.

pwm03 = 127 + (63 * p1_sw_trig) - (63 * p1_sw_top);
  #9   Spotlight this post!  
Unread 10-02-2004, 10:59
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Mapping Buttons to PWMs

Quote:
Originally Posted by Joe Ross
If you want to skip the if statement, you can use the following code

pwm03 = 127 + 63 * p1_sw_trig;

If you want your motor to be able to go backwards also, you can use 2 switches with the following code.

pwm03 = 127 + (63 * p1_sw_trig) - (63 * p1_sw_top);
just a cautionary real-world note, although this may work for the FRC, in actual C, the value of "true" for booleans is not always 1 - in fact, it's often -1.

but yes, for the FRC, one could use Joe's code.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #10   Spotlight this post!  
Unread 10-02-2004, 11:11
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Mapping Buttons to PWMs

Quote:
Originally Posted by deltacoder1020
just a cautionary real-world note, although this may work for the FRC, in actual C, the value of "true" for booleans is not always 1 - in fact, it's often -1.

but yes, for the FRC, one could use Joe's code.
Well, to be accurate, the value of true is not-false, that is, anything but 0. But p1_sw_trig is a bit, representing 1 for on, and 0 for off, so it'll be okay.

Oh, and yall don't know how lucky you have it (well, most of you do). Back in my day, we didn't have your stinkin' order of operations, and had to cram our code full of paretheses. (Or, more accurately, casually forget to do so and hit yourself when you see robot go crazy.) Yet another benefit of C over PBASIC. I, for one, am breathing a sight of relief.
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
Shortcut buttons when posting Wetzel CD Forum Support 2 10-12-2003 15:27
Looking for some help with buttons and pins... Amanda Morrison General Forum 4 26-02-2003 17:32
Assigning Joystick buttons.... archiver 2001 5 24-06-2002 00:59
Where do the stop buttons go??? archiver 2001 0 24-06-2002 00:35
How many buttons??? purplehaze357 Championship Event 0 18-04-2002 23:54


All times are GMT -5. The time now is 10:48.

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