Shop OBEX P1 Docs P2 Docs Learn Events
When is a lock needed? — Parallax Forums

When is a lock needed?

My goal is to digitally control the position of a robotic arm that has five DC motors. The idea is to place potentiometers at pivot points along the arm and control them with another set of potentiometers.
I wrote my first PASM object so I could control multiple motors with one cog. The problem is the object seems to hang at odd times.
Ultimately I want to control the arm wirelessly using a controller that mirrors the arm instead of using joysticks.

Comments

  • Post your code.

    -Phil
  • evanhevanh Posts: 15,192
    An active lock tells you not to access certain shared space for an unknown length of time. A lock serialises activity in normally concurrent environments. This is not very conducive to parallel motor control.

    I've never used one myself. I think they are mostly used for common system resource allocating schemes.

    Whatever the problem is, a lock is unlikely to help you.

  • If your code "locks up" I guess then it doesn't need a lock :)

    I've never ever needed locks and never used them but recently I had some code from one cog conflicting with a common resource on my main cog. At first glance it looked like it needed a lock around that part of the code to keep it atomic but I hated the idea of that. I solved the problem by using a different method that avoided conflicts in the first place and the code is better and faster.
  • I only have code to tweak the first two motors. If the problem is because I didn't set the clock speed for every cog then I admit I didn't even check for that possibility until Phil said to post my code.
    Even so, the PASM object probably has 'beginner' written all over it.
  • kwinnkwinn Posts: 8,697
    lardom wrote: »
    I only have code to tweak the first two motors. If the problem is because I didn't set the clock speed for every cog then I admit I didn't even check for that possibility until Phil said to post my code.
    Even so, the PASM object probably has 'beginner' written all over it.

    The cogs all run at the same speed, that which you set at the beginning of the code with the clkmode and xinfreq statements.
Sign In or Register to comment.