How to change Analog sensors polling frequency
-
I have Duet3 3HC expansion boards with my 6 Vacuum Sensors ( SMC NPN Vacuum Pressure Digital Sensors -ZSE30A-01-C-L (Not Z-Probe)) . Below is part of my config.g on my Duet3 6XD controller
; Sensors outputs ===> Duet3 inputs ; SMC NPN Vacuum Pressure Digital Sensors -ZSE30A-01-C-L (Not Z-Probe) - Model: ZSE30A-01-C-L has 2 Outputs OUT1 = 1 NPN output , OUT2 = 1 Analog Output (1 ~ 5V) ; Analog Signal Outputs (White wire (output 2) for reading Analog vacuum sensing and pressure values). M308 S0 P"2.io0.in" Y"linear-analog" A"VG1 Pressure" F0 B37 C-130 ; Duet 3 3HC CAN_ID 2 Port 0- Analog capable - Vacuum Sensor Nozzle 1 M308 S1 P"2.io1.in" Y"linear-analog" A"VG2 Pressure" F0 B35 C-130 ; Duet 3 3HC CAN_ID 2 Port 1- Analog capable - Vacuum Sensor Nozzle 2 M308 S2 P"2.io2.in" Y"linear-analog" A"VG3 Pressure" F0 B37 C-130 ; Duet 3 3HC CAN_ID 2 Port 2- Analog capable - Vacuum Sensor Nozzle 3 M308 S3 P"3.io0.in" Y"linear-analog" A"VG4 Pressure" F0 B35 C-130 ; Duet 3 3HC CAN_ID 3 Port 0- Analog capable - Vacuum Sensor Nozzle 4 M308 S4 P"3.io1.in" Y"linear-analog" A"VG5 Pressure" F0 B35 C-130 ; Duet 3 3HC CAN_ID 3 Port 1- Analog capable - Vacuum Sensor Nozzle 5 M308 S5 P"3.io2.in" Y"linear-analog" A"VG6 Pressure" F0 B35 C-130 ; Duet 3 3HC CAN_ID 3 Port 2- Analog capable - Vacuum Sensor Nozzle 6
In OpenPnP , The oversimplified sequence is :
(1) Open Vacuum
(2) Pick part
(3) Bottom Camera sequence
(4) Place part
(5) Close VacuumI am having problem with either slow readings from Duet Controller or slow reaction from OpenPnP
The issue is that after placing the part it does not get the readings in time to close the vacuum (Errors saying vacuum not off) unless
i add 300ms to the Nozzle place Dwell time. That allows OpenPnP to get the change in reading in order to close the vacuum.
if i don't add the Nozzle place dwell time (>290 ms) or just leave it at default 0 then it does not close the VacuumNOTE: i did post the same question on the OpenPnP google group and @dc42 commented that " Analog sensors on Duet boards are read every 250ms, so I think this explains your observation."
How i am reading the analog sensors values from Duet3D (testing using a macro ) or OpenPnP commands:
M118 P0 S{sensors.analog[0].lastReading} ; Check Vacuum Pressure BEFORE closing vacuum M42 P0 S0 ; Close Vacuum M118 P0 S{sensors.analog[0].lastReading} ; Check Vacuum Pressure AFTER closing vacuum
Considering what @dc42 noted, it seems analog sensor last reading values are read / updated/ polled every 250 ms .
SMC NPN Vacuum Pressure Digital Sensors -ZSE30A-01-C-L have a switch output response time of 2.5 ms or less (With anti-chattering function: 20, 100, 500, 1000, 2000 ms )
Is there a way to adjust that time frequency from 250 ms to may be every 5 ~ 20 ms if possible ? Or is there a way to configure the sensors to accomplish this ?
Looking on DWC the frequency seem to be fast enough but when reading the analog values it seems to reflect what @dc42 noted
-
@developeralgo222 there are at least three issues to consider here:
- The rate at which the sensor is read by the Duet hardware.
- The rate at which the sensor driver is polled to fetch the ADC reading and convert it to a reading in the specified range.
- The rate at which the reading from the sensor driver is sent to the main board over CAN, because the sensor is connected to an expansion board.
For #1, in this case the hardware is the internal ADC, so it's likely to be read every few milliseconds.
For #2 and #3, every 250ms the Heat task polls all the sensors and sends all the readings to the main board.Currently the firmware doesn't provide any mechanism to get readings faster than that. I can think of a few ways that we could extend the firmware to provide for getting more up-to-date readings:
- We could provide a new variant of the M308 command that takes an up-to-date reading. You would use this command before your M118 command.
- It appears to me that you simply want to compare the reading with a threshold. There is already a low-level facility in the firmware to compare an analog reading direct from the ADC with a threshold and report whenever it crosses that threshold. We could make that functionality available via a command.
Solution #1 would increase the load on the CAN bus significantly, however I guess there will be little if any motion occurring while you take these readings, in which case that wouldn't matter.
-
@dc42
Thanks for the in depth explanation. Solution 1 would probably be ideal in my case. Because i need to poll only the 6 vacuum sensors at 5 ~ 20 ms when opening and closing vacuum of each nozzle during pick and place sequence. After the OpenPnP job is run or completed i don't need to poll at those low timesis there a way that you can adjust M308 command as you said to provide up-to-date reading for individual sensors when requested in addition to the current last reading option. In my case, up-to-date reading would solve the issue
or May be add a parameter to M308 that allows for individual sensor polling but leave the rest of the sensors at default polling of 250 ms to avoid a huge load increase on CAN bus
e.g
M308 S0 P"2.io0.in" Y"linear-analog" A"VG1 Pressure" F0 B37 C-130 Tnnn
where Tnnn is the adjusted polling frequency for that Sensor otherwise default is 250 ms as usual for Duet Boards.
Any solution that is easy to implement quickly without causing a lot of issues in the Duet3D firmware code would be ideal