Hi, i’m new to these forums, though i’ve been using the modules for 6 months now.
My question is this:
I have a DC motor with an Encoder hooked up to the MotorController Module and The PulseCount. Controlling the Motor works fine, reading the pusle works fine. The problem is when i try to do both, it starts the motor, and after a long time, it finally starts reading the Count on the PulseCount Module. The Motors are used to activate a gear on a robotic hand, so they do stop moving on their own at some point. The problem is that i need to be able to read the counts as soon as it starts. I tried Threads, Timers, and so far these work even less than the solution i have. Here is the Code:
well, though i did delete the code, the basis was to start a thread, which had a while true in it , and all it did was to read the encoder. The problem with that one was that i had trouble accessing the encoder without making it static, and that created more problems.
But the one time i made it work, what happened was that because i was continuously reading it, nothing moved, so i added some suspend Thread commands while the motor was off, and resume thread the moment the motor came back on. The threads never stopped, and kept shutting off my motors.
The code is basically the same except that the following code was running in the thread
instead.
Regarding static vs non-static. You can’t access non-static members from static methods. I think your thread functions was static and that was the issue. I pretty sure you can use non-static methods as thread functions or you can always pass the class instance as a parameter to a static thread function. That way you can access any public instance properties.
Resume/suspend are “expensive”. I would use Thread.Sleep or even an event object. That way you can wait on event object to be set in your counter thread. And set it when you do need to read the counter in the main thread.
How would you go by to make that event object to control it, I’ve tried reading forums and articles, but can’t wrap my mind around how to do it. That was one thing i wanted to do but could not try, creating custom events.
And if you could supply some code that would be great! Thank you.
Alright thank you, ill try this out as soon as i can, and ill reply once i have an answer.
Again thank you, you should get an answer by sunday! (Im fairly busy until saturday!)
but now i have another problem, the GetCount property of the PulseCounts do not return a value, yet when i observe the variable, the read variable in it has a value, as well as the write values! Why can’t i access that value (its private for some odd reason) and why is get count always giving back 0?