Go to Post If it walks like a duck, and talks like a duck could be a very clever animatronics display created by Disney Imagineers.... Sometimes it is just a duck. - IKE [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-01-2012, 10:37
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
[FTC]: NXT parameter utility

I have created a nice little system for interactively setting parameters using the NXT buttons and LCD. You may find it useful. See enclosed files. Below is a summary of the utility.

Code:
/////////////////////////////////////////////////////////////////////////////
//  params.c
//
// Provides a facility for setting named parameters using the NXT LCD and buttons.
/*   
  In the user code, first each parameter and its possible values are defined using addParam()
  and addParamValue(), then getParams() is called, which starts the interactive
  parameter-setting process. getParams() returns when the user presses the
  Exit button and confirms with the Enter button.
 
    addParam( "Alliance" );    // adds one parameter
    addParamValue( "Red" );    // adds one value option to the most-recently added param
    addParamValue( "Blue" );   // adds one value option to the most-recently added param
       
    getParams();              // starts LCD/button interactive param setting process
    listParams();             // summarizes params and their values on the LCD.   
   
    getParamValueByName( "Alliance" ); // returns INDEX of the selected value option
                                       // e.g. 0 => "Red", 1 => "Blue"
    getParamValueByNumber( 0 );        // returns INDEX of the selected value option
   
 
  This facility does not support entering arbitrary values for parameters, but only
  allows choosing from a preset list of value options that are defined using addParamValue().
 
  After getParams() returns, the user code can then access the values by calling
  either getParamValueByName() or getParamValueByNumber().  Both functions return the
  INDEX of the value of the parameter. If the parameter has four possible values,
  getParamValueBy*() will return 0, 1, 2, or 3, corresponding to the order in which
  the parameter's value was added using addParamValue().

 
  The maximum number of parameters, and the maximum number or value options each
  parameter can have, are limited by two #define macros:
 
    #define MAX_PARAMS (5)        // set these no higher than
    #define MAX_PARAM_VALUES (8)  // what you need!
   
  Setting these determines how much memory is allocated for the parameters, so you
  should set these no higher than what you need.  Each parameter has one string for
  a name and MAX_PARAM_VALUES strings for the options (regardless of how many options
  are actually associated with the parameter), so the above settings would reserve
  45 strings (8+1)*5.
 
  The call to getParams() starts an interactive button-pushing process.  On the LCD,
  the first parameter is shown on one line and its first value option on the next line.
  The ">" arrow points at the parameter name to show that the arrow keys will select
  which parameter is being set.  Pressing Enter moves the ">" arrow to the parameter's
  value, showing that the arrow keys will change the value.  Pressing Enter again goes
  back to the first mode (selecting parameters).
 
  Pressing Exit will show a confirmation screen ("Params OK?").  Pressing Enter means
  "yes," and getParams() will return.  Pressing Exit means "no" and parameter setting
  continues.
 
  Usage example:
   
         task main()
         {
                  
           initParams( );
          
           addParam     ( "Color" );  // param 0
           addParamValue( "Red" );       //   value 0
           addParamValue( "Blue" );      //   value 1
         
           addParam     ( "Side" );  // param 1
           addParamValue( "Left" );      //   value 0
           addParamValue( "Right" );     //   value 1
         
           addParam     ( "Delay" );     // param 2
           addParamValue( "0 sec"  );    //   value 0
           addParamValue( "1 sec"  );    //   value 1
           addParamValue( "2 sec"  );    //   value 2
           addParamValue( "3 sec"  );    //   value 3
           addParamValue( "4 sec"  );    //   value 4
           addParamValue( "5 sec"  );    //   value 5
           addParamValue( "6 sec"  );    //   value 6
           addParamValue( "7 sec"  );    //   value 7
         
           addParam     ( "Mode" );      // param 3
           addParamValue( "ball"  );     //   value 0
           addParamValue( "park"  );     //   value 1
           addParamValue( "nada"  );     //   value 2
         
           getParams ( );  // interactive parameter selection. 
                           // Returns when user finishes selection.
          
           byte color = getParamValueByName( "Color" );
           byte side  = getParamValueByName( "Side" );
           byte delay = getParamValueByName( "Delay" );
           byte mode  = getParamValueByName( "Mode" ); 
 
 
*/
//
/////////////////////////////////////////////////////////////////////////////
Attached Files
File Type: c params.c (12.8 KB, 9 views)
File Type: c main.c (3.1 KB, 5 views)
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
Reply With Quote
  #2   Spotlight this post!  
Unread 12-01-2012, 23:43
alphadog0309's Avatar
alphadog0309 alphadog0309 is offline
Registered User
AKA: Karan Hiremath
FTC #0110 (MFS Foxes)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2008
Location: Moorestown, New Jersey
Posts: 41
alphadog0309 will become famous soon enoughalphadog0309 will become famous soon enough
Re: [FTC]: NXT parameter utility

Very cool!!!!
__________________
Karan Hiremath
FTC Team 110- MFS Foxes
Facebook: MFS Foxes
YouTube: MFS Foxes
Twitter:
@Foxes_110
Co-Captain
Head Programmer
Service Coordinator
Builder
Electrical
Reply With Quote
  #3   Spotlight this post!  
Unread 13-01-2012, 02:09
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: [FTC]: NXT parameter utility

Thanks!

I graduated from MFS -- class of 1975!
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
Reply With Quote
Reply


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


All times are GMT -5. The time now is 18:55.

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