Shared Constants
John R.
Posts: 1,376
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):
Key point being the empty "PUB Main"
Then, in multiple object files I include:
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
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. 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
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