microsoft / jacdac

Device and service catalogs for Jacdac.
https://aka.ms/jacdac
Creative Commons Attribution 4.0 International
66 stars 25 forks source link

Jacdac sending command packets during startup #1379

Open ross-inksmith opened 2 months ago

ross-inksmith commented 2 months ago

Could also be considered a feature request?

TL;DR: Control packets are sent during start up that inconsistently make servos and cause unwanted behaviour in builds, but cannot be influenced by the coder since it happens before the first line of user code is run. Simplest solution might be to remove these?

During jacdac's start up procedure for the servos it's sending a control packet to turn on and move the servo to 0°. This can happen before it reads the servo range which makes the zero point something else.

The sync() at L26 in https://github.com/microsoft/pxt-jacdac/blob/master/servo-server/server.microbit.ts seems to be the culprit, since there is no check to see if roles are assigned or start up is complete.

Would delaying any writePin until after init be possible?

ross-inksmith commented 2 months ago

Video of the issue in action Code from the video

On start up, nothing should happen until a button is pressed. A for 50% forward speed (either 45 or 135 deg), B for 20% backwards, and A+B for 0%. I'm using positonal servos since it's easier to visualize. You can see when the buttons are pressed the servos turn to the appopriate angles, but before anything is pressed the left servo (servo[0]) moves to 0 deg (aka -100%). The packet trace shows that a command is sent to the right servo (servo[2]) but it doesn't consistently react? I then power off the breakout board, and when it starts up it sets the servo[0] position again without any input.

Packet trace from the video here: video-trace.jd.txt

Alternative packet trace, startup is at about 6.5­–7s trace.jd.txt