Global Variables & Cogs
treborz17
Posts: 76
Subject:· Global Variables & Cogs
After a couple of years of working with the Basic Stamp's basic language, I find the transition to the Propeller's spin language a little overwhelming, well, at least challenging.· My main project is the completion of a Robot utilizing the Robot Base Kit and the 12V Motor Mount Kit.· By utilizing the Parallax libraries I have put together a few OBJ's that comes close to my goal of·operating an autonomous robot.
However, this is not about robots, my problem stems with my not understanding the utilization of the Spin language usage of variables and cogs.· I have an OBJ assembly of methods that does a great job of robot motor control, and another assembly of methods that do a great job of handling the 5 Ping's that I am using for avoidance control, as viewed on a LCD display.· As would be expected when all methods are included in one main object either the Ping's are not updating while a wheel is turning or a wheel movement ends prematurely if the Pings take control.· A "Catch 22".·
Obviously, this is where the multi cog ability of the propeller takes over.· Where my lack of ability lies, is not understanding how to communicate with a cog.· As soon as I put the Ping scanning methods in a "cognew" ·I lose the ability to address from the main method, the Global VARiables I have defined to contain the five Ping Sensor's distance measurement.
I got to thinking while writing this post, that maybe this should be a task that utilizes the sending of data serially from the ping-method-cog to variables in the main method?
I have spent days reviewing all of the available Parallax lititure on the subject, and am not quite able to overcome this problem.· Any assistance would really be appreciated.
Robert
·
After a couple of years of working with the Basic Stamp's basic language, I find the transition to the Propeller's spin language a little overwhelming, well, at least challenging.· My main project is the completion of a Robot utilizing the Robot Base Kit and the 12V Motor Mount Kit.· By utilizing the Parallax libraries I have put together a few OBJ's that comes close to my goal of·operating an autonomous robot.
However, this is not about robots, my problem stems with my not understanding the utilization of the Spin language usage of variables and cogs.· I have an OBJ assembly of methods that does a great job of robot motor control, and another assembly of methods that do a great job of handling the 5 Ping's that I am using for avoidance control, as viewed on a LCD display.· As would be expected when all methods are included in one main object either the Ping's are not updating while a wheel is turning or a wheel movement ends prematurely if the Pings take control.· A "Catch 22".·
Obviously, this is where the multi cog ability of the propeller takes over.· Where my lack of ability lies, is not understanding how to communicate with a cog.· As soon as I put the Ping scanning methods in a "cognew" ·I lose the ability to address from the main method, the Global VARiables I have defined to contain the five Ping Sensor's distance measurement.
I got to thinking while writing this post, that maybe this should be a task that utilizes the sending of data serially from the ping-method-cog to variables in the main method?
I have spent days reviewing all of the available Parallax lititure on the subject, and am not quite able to overcome this problem.· Any assistance would really be appreciated.
Robert
·
Comments
Thank you for your response -- I thought I had tried that. However, in looking over my old design copies, and with your confirming what I already thought was the correct way to include the cog, I see that maybe I had some other issues causing some of my problem. I will setup what you have suggested, and be sure that I have done it correct, try it again and I'll let you know how it went.
Thanks again,
Robert
doc v1.2 page 212:
During compilation of an object, all declarations in its collective VAR blocks are grouped together by type. The variables in RAM are arranged with all the longs first, followed by all words, and finally by all bytes. This is done so that RAM space is allocated efficiently without unnecessary gaps. Keep this in mind when writing code that accesses variables indirectly based on relative positions to each other.
So we can pass the pointer of the first variable.
As reported by Duane
We just need to declare vars in this order, all same type together.