Shop OBEX P1 Docs P2 Docs Learn Events
Cog Objects — Parallax Forums

Cog Objects

EdKirkEdKirk Posts: 27
edited 2006-11-23 14:15 in Propeller 1
Guys,

I have met with some success in programming my robot with spin code.

I am now ready to start another cog, so that I can read commands from the radio receiver and overlap output to the robot motors at the same time.··After many trials I am asking for help.

I would slightly prfer to use CogInit rather than CogNew so that I will feel that I know what is happening.· Perhaps I need to review object programming.

But how do I know which objects are actually loaded into a given Cog?·

Will the code need to be in a different place?·

In which object should the ConInit command be placed?

Where do I specify local ram?· Global ram?

Ed

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-16 22:37
    If you are writing in SPIN, the SPIN interpreter is what gets loaded into the cog. This is the form of COGNEW or COGINIT that has a SPIN method call as the first parameter and the address of a stack area as the second parameter. The stack area is used for local variables and temporaries as well as return addresses. The SPIN interpreter reads the interpretive SPIN codes out of main memory just like the main program itself. The SPIN interpretive code is reentrant so any number of SPIN interpreters can be executing the same byte codes. Variables declared with VAR or DAT are common and you have to use some kind of negotiating (like LOCKxxx) to prevent two cogs from trying to change the same variables at the same time.

    The COGINIT should be placed in the object containing the initial method to be called. COGINIT in SPIN requires you to know what cog you want to use. Since they're all identical, many existing objects use COGNEW. You'd have to keep track of what cogs are available if you're using any library routines that start up a cog. Better to let the hardware do it and use COGNEW.
  • EdKirkEdKirk Posts: 27
    edited 2006-11-17 12:02
    Thank you Mike Green,

    A wise man once wrote, "I apologize for making this letter so long.· I did not have time to write a short one."

    So I am forced to document my planned use of my PropStick using several cogs; I really needed to do that anyway instead of working from my head with its many faults.

    It will take a few days to do so.· I plan to then submit my cog questions in a broader context.

    OK?· No reply needed now.

    EdKirk

  • EdKirkEdKirk Posts: 27
    edited 2006-11-18 17:56
    Hi,

    The attached drawing shows what I am planning to get· more complete control of my VEX robot.· The short low levels shown cause the motor to reverse; long ones cause motor to spin forward.· I need to control how the joy stick inputs are shared and mixed·to control how the three wheeled robot can move forward and back, left and right, rotate cw or ccw, or travel in a curve.· That mixing may require some approximate trig functions.

    If the operator watches the robot he gets all mixed up since his left and right keep rotating relative to those of the·robot.· The onboard camera is independent of the controller and sends a forward looking picture to a monitor so that the operator can see what the robot "sees" thus keeping his left and right coordinated with those of the robot.

    Now for my cog question.·

    I am using Martin's BS2 to observe the time of the low level pulses·received and sent by the Prop Stick.· That uses·some additional Cogs.

    I plan to used 1 Cog to continuously monitor the incoming·pulse widths·from the radio receiver and another to issue a continuous stream of output pulses to the VEX controller which contains the power amplifiers for the PWM control of each motor.· I guess I can have about a 50% overlap in the received and sent streams which will cause a delay of about 10 msec for the Prop Stick to add its brains to the control.

    Although I thought I had studied the spin chapters of the·very fine Prop manual·thoroughly, I still have questions:

    The VAR object given in the examples never have a name attached.· Does that mean that there can be only one such object which defines the·names of global varialbles?· Or can VAR be repeated·with in·each Cog for local variables?

    ln the examples the local variables dedicated to a given Cog are in an array.· Does that mean that·local variables·can only be given subscript numbers and not· meaningful names?

    In Pascal 7.0 with which I am quite familiar variables can have several subscripts so that two, three,·and·even four dimensional arrays can be used.· Is that possible in SPIN?· That would be convenient here since the global variables will·contain the·modified pulse widths for each motor but the use of those widths be each motor are identical.

    Would it be better to use a sepearate Cog for each motor?

    I still cannot discern whether the COGNEW or COGINIT commands should be contained within the Cog object or· must·they be specied·earlier?

    I am certain my questions are of the kindergarten variety·but I would·like some hints.

    Thanks,

    EdKirk
    edk@wi.rr.com
  • LawsonLawson Posts: 870
    edited 2006-11-18 18:45
    by the way, the timing format described above is the standard format for AM and FM radio control car/airplane equipment. If you poke arround with a 'scope in a reciever or transmetter from one of these systems one of the traces will have an identical signal. (ofc it'll only have as many pulses after the sync pulse as it has channels.) well, I think standard RC stuff uses a bit longer of a pulse per channel. about 1.5ms +- 1ms full range +-0.5ms typical. I think that you'll find the "sync" pulse is of variable length too.

    And now you know!
    marty
  • EdKirkEdKirk Posts: 27
    edited 2006-11-19 15:08
    MARTY,

    Thanks for the more complete report on RC's in general.

    EdKirk
  • EdKirkEdKirk Posts: 27
    edited 2006-11-23 11:49
    Guys,

    I apparently terminated this thread Unintentionally.

    I thanked Marty for enlarging my knowledge, but I did not intend for the long list of questions contained in my request of 11/18 to be forgotten.

    Here they are again.

    Although I thought I had studied the spin chapters of the very fine Prop manual thoroughly, I still have questions:

    The VAR object given in the examples never have a name attached. Does that mean that there can be only one such object which defines the names of global varialbles? Or can VAR be repeated with in each Cog for local variables?

    ln the examples the local variables dedicated to a given Cog are in an array. Does that mean that local variables can only be given subscript numbers and not meaningful names?

    In Pascal 7.0 with which I am quite familiar variables can have several subscripts so that two, three, and even four dimensional arrays can be used. Is that possible in SPIN? That would be convenient here since the global variables will contain the modified pulse widths for each motor but the use of those widths be each motor are identical.

    Would it be better to use a sepearate Cog for each motor?

    I still cannot discern whether the COGNEW or COGINIT commands should be contained within the Cog object or must they be specied earlier?

    I am certain my questions are of the kindergarten variety but I would like some hints.

    Thanks,

    EdKirk
    edk@wi.rr.com
  • EdKirkEdKirk Posts: 27
    edited 2006-11-23 14:15

    Although I thought I had studied the spin chapters of the·very fine Prop manual·thoroughly, I still have questions:

    The VAR object given in the examples never have a name attached.· Does that mean that there can be only one such object which defines the·names of global varialbles?· Or can VAR be repeated·with in·each Cog for local variables?

    ln the examples the local variables dedicated to a given Cog are in an array.· Does that mean that·local variables·can only be given subscript numbers and not· meaningful names?

    In Pascal 7.0 with which I am quite familiar variables can have several subscripts so that two, three,·and·even four dimensional arrays can be used.· Is that possible in SPIN?· That would be convenient here since the global variables will·contain the·modified pulse widths for each motor but the use of those widths be each motor are identical.

    Would it be better to use a sepearate Cog for each motor?

    I still cannot discern whether the COGNEW or COGINIT commands should be contained within the Cog object or· must·they be specied·earlier?

    I am certain my questions are of the kindergarten variety·but I would·like some hints.

    Thanks,

    EdKirk
    edk@wi.rr.com
Sign In or Register to comment.