Shop OBEX P1 Docs P2 Docs Learn Events
Can Ping values be represented graphically? — Parallax Forums

Can Ping values be represented graphically?

lardomlardom Posts: 1,659
edited 2013-03-15 08:45 in General Discussion
I'm working on a project that controls two steppers differentially. The left and right motor objects are in separate cogs. They call a Ping object which returns values that get evaluated by 'case' in the motor objects. If I comment out the call to Ping and write the value in myself the motors work perfectly. I get weird behavior from the Ping like wheels chattering and locking up. I even placed a delay of 1.5 seconds between Ping returns to see what would happen.
I want to design an object that works similar to a joystick because I'm wondering if I'm missing something when debugging on the PST. Is there a similar debugging method?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-03-15 08:38
    You can't call the same PING object from two different cogs without locks. What happens is that one stepper cog calls the PING object and, before the PING object gets to finish, the second stepper cog calls it and interrupts the PING operation which produces a garbage result. You can either use locks (semaphores) so that only one stepper cog at a time can use the PING object while the other has to wait its turn or you have to change the logic around so that the stepper cogs pick up their speed and direction information from a variable and you have another cog that does the PING calls, decides how fast the steppers have to go and sets the shared variables for the stepper cogs to find. Really, the stepper cogs should be just concerned with driving the steppers. If not, you get choppy movement as the driver has to do something that takes some time and the stepper pulses get interrupted.

    You could certainly use one of the TV or VGA objects for a debug display, particularly if you have extra I/O pins. I've used Cluso99's 1-pin TV driver for this since black & white is all I'd need for debugging. You can do graphics if you have enough memory for the buffer or a text display if you only have enough memory for a text buffer. You can use the graphics characters in the ROM font for simple drawing and graphs. It's rough, but works.
  • lardomlardom Posts: 1,659
    edited 2013-03-15 08:45
    Mike. You are the best. Thanks!
Sign In or Register to comment.