Hello,
I am working on a machine that is an arm attached to a pneumatic rotary actuator with an encoder attached to the shaft and an piezoelectric impact sensor at the end of the arm. The function of the machine has three phases that I need to repeat a set number of times:
- Phase 1 should open a solenoid to rotate the actuator clockwise until a specified angle is reached then hold that position for a specified time, then close said solenoid.
- There is a hard stop at the "high" position of the arm so really this step is just raise the arm up and wait for a specified time - there isn't actually any fine position control needed.
- Phase 2 should open a second solenoid to rotate the actuator counterclockwise until a specified rotational velocity is reached then close the second solenoid.
- The velocity needs to be calculated as I can only collect angle data and elapsed time.
- Phase 3 should wait for a specified time
I would like to be able to plot the position and velocity data for the entire set of cycles (ideally in real time but understandable if this isn't doable).
I am trying to use the daqmx python library to read the encoder data and control the analog output signals to the two solenoids. I have attached my current .py file that sort of works.
The arm moves up to the specified angle and waits as it should during phase 1. The arm starts to swing down and sometimes triggers the velocity event. When the velocity event does trigger, the code waits as it should during phase 3, and repeats. The plotly graphs look as I would expect although when I ported the data to excel and plotted it there, there were significant gaps in the data which tells me some samples aren't actually getting collected and perhaps plotly is "filling in the gaps".
I am having a hard time understanding how the sample rate, samples per channel, and innate frequency of the main while loop are playing together to determine the actual data collection frequency. If I adjust the sample rate and samples per channel values, it seems like some data gets lost and the velocity target event won't trigger.
tl;dr: how do I continuously collect encoder data at a fairly high speed, read the data to do real time (or close to) calculations, and write analog signals based on the results of the calculations?
Any help would be greatly appreciated!