Closed fnoop closed 7 years ago
Got it working on the pi by adding two things. The first by adding a boolean to make sure start() and stop() only get called once, since when controlprocessing=False it flooded the subprocess with SIGUSR1.
In main loop in visionlanding
tracking = False
while True:
# If craft mode has changed, take action
if (args.controlprocessing and (craft.vehicle.armed and (craft.vehicle.mode == "LAND" or (craft.vehicle.mode == "LOITER" and (craft.precloiter_opt and craft.vehicle.channels[str(craft.precloiter_opt)] > 1800))))) and track_targets.state != "started" and not tracking:
track_targets.start()
tracking = True
elif (args.controlprocessing and (not craft.vehicle.armed or (craft.vehicle.mode != "LAND" and (craft.vehicle.mode != "LOITER" and (craft.precloiter_opt and craft.vehicle.channels[str(craft.precloiter_opt)] <= 1800))))) and track_targets.state == "started" and tracking:
track_targets.stop()
tracking = False
elif not args.controlprocessing and not track_targets.state and not tracking:
track_targets.start()
tracking = True
and the second was by adding a sleep right after track_targets is launched to make sure that initial start signal gets to it.
In TrackTargets.init
# Launch tracking process and process output
log.info("Launching track_targets with arguments:" + " ".join(self.track_arguments))
self.launch()
log.info("Sleeping for 10 seconds...")
sleep(10)
Didn't make a PR because there is almost definitely a more elegant way of doing this, but maybe this will help.
Revamped the tracking object and track_targets output to track the state better, including initialisation. This issue was related to slower platforms taking a while to start up the track_targets process and vision_landing sending the SIGUSR1 before the signal handling in track_targets was setup. Default handling of SIGUSR1 is to terminate. Instead, track_targets now sends a specific message once initialised which vision_landing waits for, before trying to send the signal to start tracking.
It looks like track_targets is shut down and returns -10 return code, which corresponds to being killed by sig 10 (SIGUSR1).
vision_landing uses SIGUSR1 to command track_targets to wake up and start processing:
When run by hand outside of vision_landing master process, it seems to work fine: