Writing variables in a cog and reading it in another cog
Cats92
Posts: 149
Hello,
I meet problems with a program which reads data from 3 Sharp GP2DO2 IRdetectors and uses this data to modify servocommands.
Three variables (irdetectleft, irdetectright,irdetectfront) are used by 2 cogs : one cog reads the IRdetectors in a repeat loop , with a shiftin function and updates the 3 variables , the other cog reads this variables in another loop and modify servo commands accordingly.
This works well with 2 IR detectors (left and right) but when I add front , this Irdetector gives an irdetectfront value which remains 0 .
(each Irdetecor works well when tested alone and I used 2 different batteries : one for the propeller, one for motors and detectors. The cog is declared with a long stack3[noparse][[/noparse]50] var)
Is it a problem of concurrent read/write access to the 3 shared variables?
A problem of timing ? or electricity consumption ?
Beginning with Propeller, I dont understand well what to do when updating a variable in a cog and reading its value in another cog.
When is it usefull to lock ? and how to do it efficiently ?
Here is the program I use.
Thanks for help.
·
I meet problems with a program which reads data from 3 Sharp GP2DO2 IRdetectors and uses this data to modify servocommands.
Three variables (irdetectleft, irdetectright,irdetectfront) are used by 2 cogs : one cog reads the IRdetectors in a repeat loop , with a shiftin function and updates the 3 variables , the other cog reads this variables in another loop and modify servo commands accordingly.
This works well with 2 IR detectors (left and right) but when I add front , this Irdetector gives an irdetectfront value which remains 0 .
(each Irdetecor works well when tested alone and I used 2 different batteries : one for the propeller, one for motors and detectors. The cog is declared with a long stack3[noparse][[/noparse]50] var)
Is it a problem of concurrent read/write access to the 3 shared variables?
A problem of timing ? or electricity consumption ?
Beginning with Propeller, I dont understand well what to do when updating a variable in a cog and reading its value in another cog.
When is it usefull to lock ? and how to do it efficiently ?
Here is the program I use.
Thanks for help.
·
Comments
In your case, presumably your detector samples are independant. If they are read as 3 LONGs (or words or bytes) it doesn't matter if one has been updated to the latest sample but the other two are still on the previous sample. So you don't need a lock.
Did you mean to attach your code?
This time i try to join my code
I don't know why you are having problems with the 3rd sensor.
It remains that with three detectectors the last read did not work , if i use only two of them they give good readings.
Any idea about what may happen ?
Finally I changed the pins for the third IR detector (put it on 9,8 instead of 7,6) and after that it works.
Perhas a pin has some damage with a previous program or connection ?
Thanks for your help