Shop OBEX P1 Docs P2 Docs Learn Events
Shared Constants — Parallax Forums

Shared Constants

John R.John R. Posts: 1,376
edited 2010-03-29 01:19 in Propeller 1
I am working on a Prop based CNC program, and have a need/desire to share a number of constants between files.

I have come up with the following method, and am wondering if there are any hidden traps, or a better way to do this.

First (well not first, but my first step in getting constants defined in only one place), I created a file "Constants.spin" with the following contents (shown abbreviated):

CON
  ''
  ''*********************
  ''Parameter Definitions
  ''*********************
  ''
  XAxis         = 0             ''XAxis: X Index for Parameters
  YAxis         = 1             ''YAxis: Y Index for Parameters
  ZAxis         = 2             ''ZAxis: Z Index for Parameters
  AAxis         = 3             ''AAxis: A Index for Parameters
  BAxis         = 4             ''BAxis: B Index for Parameters
  CAxis         = 5             ''CAxis: C Index for Parameters

  AxisCount     = 6             ''AxisCount: Number of Axis (for Parameter Constant Definition)
    
  AxisPos       = AxisCount * 0             ''AxisPos: Positions for Encoder Object (Space for 6 Axis)
  G28Home       = AxisCount * 1             ''G28Home: Primary Home Positions
  G30Home       = AxisCount * 2             ''G30Home: Alternate Home Positions
  CmdStartPos   = AxisCount * 3             ''CmdStartPos: Command Start Positions (6 Axis)
  CmdEndPos     = AxisCount * 4             ''CmdEndPos: Command End Positions (6 Axis)
  
  'snip....

PUB Main





Key point being the empty "PUB Main"

Then, in multiple object files I include:

OBJ
  Cons   : "Cosntants.spin"





And use the Cons#XAxis convention.

Is the empty PUB Main going to come back and bite me?

Are there other ways to do this?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log

Comments

  • Timothy D. SwieterTimothy D. Swieter Posts: 1,613
    edited 2010-03-28 23:11
    John - I'd say that your method of sharing the constants is clever. When I read the description of your problem I had a similar thought as to how you do it. I haven't done this myself so I am not sure if you will run into any trouble with it. Anyone used the method John described? Any problems with it?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Timothy D. Swieter, E.I.
    www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" 16:9 LCD Composite video display, eProto for SunSPOT, PropNET, PolkaDOT-51
    www.tdswieter.com
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-03-29 00:44
    The empty PUB Main should not be a problem. It has to be there just so the program will compile. It's too bad we don't have an #INCLUDE file capability in the Prop Tool (Jeff - hint, hint), as that would eliminate both the necessity for a PUB method as well as the requirement to prepend each constant with an OBJ# prefix.

    -Phil
  • John R.John R. Posts: 1,376
    edited 2010-03-29 01:19
    Thanks guys. I haven't gotten in too deep on the project yet, but so far, no problems with this.

    I'll second the #INCLUDE directive...

    I'm reading encoders, and driving servos motors (as in DC Motors with a driver and the encoders). I'm starting to work on motion control. I'm sure there is some code out there to be had, but I'm kind of working in a vacuum on some of this on purpose, just for the "personal learning" experience.

    I need to get some pics, etc. up, but it's the old "work on public visibility, or work on the project" syndrome...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
Sign In or Register to comment.