How to use same program on 4 cogs?
For 4 motors using 4 cogs and the same code on each, only changing the Step and Dir pins plus variables, I am looking for a way to use the same code without having to copy and paste it over and over again as the code gets edited. The code is long, and each time I copy and paste code for motor X to the other 3 cogs, I am having to go through it and type over the "X" places with the correct new letter, Y, Z, or R.
Here is my only thought to solve it: Let the code be only in one method, but it gets passed parameters for the 2 pins from the new cog like shown below, then each cog runs the program using the pins it got passed. Is this the best plan for what I want to do?
There are also 6 variables used in the code with names associated with each motor, i.e. Xaccel, Xdecel, Xarate, Xdrate, Xcurrent, Xrun, Xrun80. How to have one code block use 4 sets of variables? Passing the pins are easy, how do I pass the variable names to use for each case?
Thanks for any suggestions
Post Edited (originator) : 2/2/2007 9:08:05 AM GMT
Here is my only thought to solve it: Let the code be only in one method, but it gets passed parameters for the 2 pins from the new cog like shown below, then each cog runs the program using the pins it got passed. Is this the best plan for what I want to do?
PUB Start cognew (movex, @stack1) cognew (movey, @stack2) cognew (movez, @stack3) cognew (mover, @stack4) PUB moveX motor_control(0, 1) PUB moveY motor_control(2, 3) PUB moveZ motor_control(4, 5) PUB moveR motor_control(6, 7) PUB moter_control(Step, Dir) 'run the motor on pins rec'd
There are also 6 variables used in the code with names associated with each motor, i.e. Xaccel, Xdecel, Xarate, Xdrate, Xcurrent, Xrun, Xrun80. How to have one code block use 4 sets of variables? Passing the pins are easy, how do I pass the variable names to use for each case?
Thanks for any suggestions
Post Edited (originator) : 2/2/2007 9:08:05 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Thanks Paul
Post Edited (originator) : 2/2/2007 8:49:45 PM GMT
accel := LONG[noparse][[/noparse]radr]
will get the LONG variable (4 bytes worth is a long) starting at the memory location passed in radr
decel := LONG[noparse][[/noparse]radr + 4]
will get the variable starting 4 bytes higher that the address radr points to and
ramp := LONG[noparse][[/noparse]radr + 8]
will get the next variable "slot", and yes, to get the fourth, add 12 and so on.
The factor of "4" is how many bytes a LONG takes in memory.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Link to My Nomad Build Log
And one important note about this technique is you cannot mix data types in the same record, because the compiler groups all similar types together (LONGs with LONGs, WORDs with WORDs, BYTEs with BYTEs). So if you try to create a record consisting of LONGs and WORDs the compiler will physically seperate them so you cannot know what the proper offset is to get to the next data type.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 2/2/2007 9:09:27 PM GMT
**Aha! of course it does***
Post Edited (originator) : 2/3/2007 7:21:19 AM GMT