Hello,
We have a Dry Hopper spreader for our drone. The spreader system contains an optical sensor for recognizing when the hopper is empty versus not empty. We’re attempting to query the sensor in Lua scripting, but not having any luck. Hoping someone can point me in the right direction.
Configuration
- Cube Orange+
- ESP200 Spreader System. Optical Empty sensor connected to AUX5.
- Parameter Settings:
- SERVO13_FUNCTION: -1 (GPIO)
- RPM1_TYPE: 2 (GPIO)
- RPM1_PIN: 54 (AUX 5)
Expected readings from Optical Empty Sensor
- Hopper empty: 0v
- Hopper not empty: 5v
Solution A
Outside of Update Loop
local EMPTY_SENSOR_PIN = 13
local empty_sensor = analog:channel()
if not empty_sensor:set_pin(EMPTY_SENSOR_PIN) then
log_error(ADSST_ERROR.ID_003, string.format("Error setting Analog Empty Sensor Pin: %d", EMPTY_SENSOR_PIN))
empty_sensor = nil
end
Within Update Loop
if empty_sensor ~= nil then
log_info(ADSST_INFO.ID_004, string.format("Analog Empty Sensor Voltage %0.2f", empty_sensor:voltage_latest()))
end
Test Results
- Function call empty_sensor:set_pin(EMPTY_SENSOR_PIN) returns true.
- No obstruction in path of optical beam: Continuously receive voltage reading anywhere between 0.49 and 0.50
- Place obstruction in path of optical beam: Continuously receive voltage reading anywhere between 0.49 and 0.50
Solution B
Outside of Update Loop
local EMPTY_SENSOR_PIN = 54
local empty_sensor = PWMSource()
if not empty_sensor:set_pin(EMPTY_SENSOR_PIN) then
log_error(ADSST_ERROR.ID_003, string.format("Error setting PWM for Empty Sensor Pin: %d", EMPTY_SENSOR_PIN))
empty_sensor = nil
end
Within Update Loop
if empty_sensor ~= nil then
log_info(ADSST_INFO.ID_004, string.format("PWM Empty Sensor reading: %d", empty_sensor:get_pwm_us()))
end
Test Results
Function call empty_sensor:set_pin(EMPTY_SENSOR_PIN) returns false.
Solution C
Within Update Loop
local empty_sensor_reading = RPM:get_rpm(0)
if empty_sensor_reading ~= nil then
log_info(ADSST_INFO.ID_004, string.format("RPM Empty Sensor reading: %d", empty_sensor_reading))
else
log_error(ADSST_ERROR.ID_003, "Error obtaining RPM Empty Sensor reading.")
end
Test Results
Function call RPM:get_rpm(0) consistently returns false, regardless whether or not the optical sensor is blocked.
Conclusion
I am thinking that I am on the right track with Solution A, yet the voltage readings remain consistent regardless of whether the optical sensor beam is blocked or not blocked.
Suggestions that anyone may have are greatly appreciated.
Regards,
Dave