Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base input fix #1636

Merged
merged 1 commit into from
Dec 6, 2022
Merged

Base input fix #1636

merged 1 commit into from
Dec 6, 2022

Conversation

DTCurrie
Copy link
Member

@DTCurrie DTCurrie commented Dec 2, 2022

This PR updates how we process base input events to make sure they are processed in order and to avoid race conditions. Instead of immediately triggering events, we add them to a queue and resolve them one-by-one. The stop and digestInput functions were refactored to return promises that did not resolve until the callback for their respective gRPC calls is invoked. This way if inputs are pressed rapidly, we make sure a set power event is resolved before calling the subsequent stop call.

Here is my console log after spamming the d key:

Screen Shot 2022-12-02 at 6 00 20 PM

@micheal-parks @edaniels @stevebriskin If we know how to reproduce this issue it would be great to test out this PR with an actual bot. I am hoping this will be a better solution than having to set a timeout to wait for stops.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 2, 2022
onMounted(() => {
initStreamState();
window.addEventListener('visibilitychange', handleVisibilityChange);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well stop anything that is going on if someone navigates away from the window. Just some extra fallbacks.

@DTCurrie DTCurrie self-assigned this Dec 2, 2022
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 2, 2022
@micheal-parks
Copy link
Member

I have a few worries about this approach: what we're implementing here should have similar architecture to a networked multiplayer game, and it's not recommended practice there to have an across-the-stack event loop where digesting a stack of user inputs is network-bound. With this solution I worry that we'll often start seeing perceptible out of sync commands. I'd recommend doing what is often done with multiplayer games: we send the client's current state (with regard to which input is pressed) at a 16.6ms interval without waiting for responses and let the robot figure out what to do with the given information. I remember briefly discussing something like this idea with Eric and Matt, and it being mentioned that this above approach might mess with people who are also scripting their robots while controlling? Regardless, I'm not sure how we give a good long term UX without implementing some form of the solution I just mentioned. Would love to hear thoughts or counterpoints.

@DTCurrie
Copy link
Member Author

DTCurrie commented Dec 5, 2022

I have a few worries about this approach: what we're implementing here should have similar architecture to a networked multiplayer game, and it's not recommended practice there to have an across-the-stack event loop where digesting a stack of user inputs is network-bound. With this solution I worry that we'll often start seeing perceptible out of sync commands. I'd recommend doing what is often done with multiplayer games: we send the client's current state (with regard to which input is pressed) at a 16.6ms interval without waiting for responses and let the robot figure out what to do with the given information. I remember briefly discussing something like this idea with Eric and Matt, and it being mentioned that this above approach might mess with people who are also scripting their robots while controlling? Regardless, I'm not sure how we give a good long term UX without implementing some form of the solution I just mentioned. Would love to hear thoughts or counterpoints.

I see what you mean but I am not sure how we would implement that without some sort of service on the robot that receives those client calls on the robot side. As it stands the RC is basically acting as that service.

If we are worried about out of sync commands then we need to cancel and stop whatever current digestion is happen and then start a new process whenever a new input is pressed. That would mean if you change directions the robot would have a brief stop between changing directions.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 5, 2022
@DTCurrie
Copy link
Member Author

DTCurrie commented Dec 5, 2022

@edaniels @micheal-parks @stevebriskin Ok so tried to simplify this a bit. All we do now is just check if there are no pressed keys after a digestInput call resolves and if so we call stop.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 5, 2022
@DTCurrie DTCurrie requested a review from edaniels December 5, 2022 20:52
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 5, 2022
@DTCurrie
Copy link
Member Author

DTCurrie commented Dec 5, 2022

@edaniels @AdamMagaluk Seeing differences in main.css from the CI to my local. Can't get it to regenerate on my local.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

Code Coverage

Note: merge base coverage results not available, comparing against closest 75aa7fd~1=(d29588c) instead

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 61% 0.00%
go.viam.com/rdk/components/arm/universalrobots 13% 0.00%
go.viam.com/rdk/components/arm/xarm 2% 0.00%
go.viam.com/rdk/components/arm/yahboom 7% 0.00%
go.viam.com/rdk/components/audioinput 55% 0.00%
go.viam.com/rdk/components/base 67% 0.00%
go.viam.com/rdk/components/base/agilex 62% 0.00%
go.viam.com/rdk/components/base/boat 41% 0.00%
go.viam.com/rdk/components/base/wheeled 76% 0.00%
go.viam.com/rdk/components/board 68% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/commonsysfs 47% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi 50% 0.00%
go.viam.com/rdk/components/camera 65% 0.00%
go.viam.com/rdk/components/camera/fake 67% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 77% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 77% -0.33%
go.viam.com/rdk/components/camera/videosource 56% +0.51%
go.viam.com/rdk/components/encoder/fake 77% 0.00%
go.viam.com/rdk/components/gantry 68% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 84% +1.11%
go.viam.com/rdk/components/gantry/oneaxis 86% 0.00%
go.viam.com/rdk/components/generic 83% 0.00%
go.viam.com/rdk/components/gripper 80% 0.00%
go.viam.com/rdk/components/input 87% 0.00%
go.viam.com/rdk/components/input/gpio 83% 0.00%
go.viam.com/rdk/components/motor 81% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 63% 0.00%
go.viam.com/rdk/components/motor/dmc4000 69% 0.00%
go.viam.com/rdk/components/motor/fake 57% 0.00%
go.viam.com/rdk/components/motor/gpio 64% +2.16%
go.viam.com/rdk/components/motor/gpiostepper 57% +0.59%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 40% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 37% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 28% 0.00%
go.viam.com/rdk/components/posetracker 86% 0.00%
go.viam.com/rdk/components/sensor 86% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 34% 0.00%
go.viam.com/rdk/components/servo 78% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 76% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 77% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 70% 0.00%
go.viam.com/rdk/motionplan 71% +2.79%
go.viam.com/rdk/octree 93% 0.00%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 71% 0.00%
go.viam.com/rdk/protoutils 62% 0.00%
go.viam.com/rdk/referenceframe 69% 0.00%
go.viam.com/rdk/registry 88% 0.00%
go.viam.com/rdk/resource 83% 0.00%
go.viam.com/rdk/rimage 78% 0.00%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 73% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 93% 0.00%
go.viam.com/rdk/robot/client 79% 0.00%
go.viam.com/rdk/robot/framesystem 68% 0.00%
go.viam.com/rdk/robot/impl 81% -0.24%
go.viam.com/rdk/robot/server 58% 0.00%
go.viam.com/rdk/robot/web 60% 0.00%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/armremotecontrol 71% 0.00%
go.viam.com/rdk/services/armremotecontrol/builtin 25% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 66% 0.00%
go.viam.com/rdk/services/datamanager 65% 0.00%
go.viam.com/rdk/services/datamanager/builtin 80% 0.00%
go.viam.com/rdk/services/datamanager/datacapture 21% 0.00%
go.viam.com/rdk/services/datamanager/datasync 72% 0.00%
go.viam.com/rdk/services/motion 63% 0.00%
go.viam.com/rdk/services/motion/builtin 88% 0.00%
go.viam.com/rdk/services/navigation 54% 0.00%
go.viam.com/rdk/services/sensors 77% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 14% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 72% 0.00%
go.viam.com/rdk/services/vision 80% 0.00%
go.viam.com/rdk/services/vision/builtin 74% 0.00%
go.viam.com/rdk/spatialmath 85% 0.00%
go.viam.com/rdk/subtype 96% 0.00%
go.viam.com/rdk/utils 71% +0.19%
go.viam.com/rdk/vision 26% 0.00%
go.viam.com/rdk/vision/chess 80% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 82% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 26% 0.00%
Summary 66% (19804 / 29973) +0.23%

@DTCurrie DTCurrie merged commit 3bb363c into viamrobotics:main Dec 6, 2022
@DTCurrie DTCurrie deleted the base-input-fix branch December 6, 2022 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants