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

Add support for MPU6050 accelerometer/gyroscope [RSDK-868] #1611

Merged
merged 16 commits into from
Dec 2, 2022

Conversation

penguinland
Copy link
Member

Tried with the chip on a breadboard wired to a raspberry pi: seems to work adequately. We only get updates twice per second on app.viam.com (and only angular velocity), but in theory you should be able to go much faster, and thereby get more interesting data from writing your own app.

There's something wrong with getting the raw readings: I had expected to be able to see the temperature and linear acceleration via the app, but that's not quite working yet. but I figured I should get the PR out to get more eyes looking at it, even before I've finished tweaking the final details.

@penguinland
Copy link
Member Author

This PR is uncomfortably long. For next time, do you see a way I should have split it up into smaller pieces?

@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 Nov 22, 2022
@penguinland
Copy link
Member Author

(The changes to the .js files are solely from running make build. I did not intend to modify those files myself.)

Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

This PR size is fine for adding a model. There are no worries there, it's just the amount of code that goes into writing a driver. Do not worry about the frontend folder either.

It's looking good, done with first pass. A few nits here and there, and one major question about when we poll the sensor for information/how continuously we poll. Right now we're limited by snapshots from when we request AngularVelocity and Readings, and not polling continuously in the background.

components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Show resolved Hide resolved
@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 Nov 23, 2022

func (mpu *mpu6050) Readings(ctx context.Context, extra map[string]interface{}) (map[string]interface{}, error) {
mpu.mu.Lock()
defer mpu.mu.Lock()
Copy link
Member Author

Choose a reason for hiding this comment

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

🤦 Well there's yer problem! After calling this function, the mutex never gets unlocked, which means no other values can be read afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

...and it's worse than that! By deferring a second Lock(), we have a deadlock in the deferred part of the function, which is why we don't even get a response from the first call to the readings.

@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 1, 2022
@penguinland
Copy link
Member Author

Sorry about the delay getting back to this. I've added in the background goroutine you suggested, and we can now get all the readings from the chip without it locking up. Take another look!

Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

looks good. one little comment/units nit in Angular velocity. Otherwise great job!

components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
components/movementsensor/mpu6050/mpu6050.go Outdated Show resolved Hide resolved
@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 1, 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 1, 2022
@penguinland
Copy link
Member Author

Background goroutine refactored!

My only lingering doubt is that the temperature sensor always reads 35-37 degrees Celcius, whereas I'd expect something closer to 23. This chip really shouldn't be running hot, should it? and yet, page 30 of this PDF sure implies that I've got the values correct. Maybe the thermometer isn't nearly as reliable as I had expected? I'm inclined to merge this even if the thermometer does weird things. If there's a bug, we can deal with it later.

@penguinland
Copy link
Member Author

...okay, one more doubt: github's CI complains that "make build lint resulted in changes not in git," but running make build lint on my local machine results in no changes, and pushing to github shows that everything is up-to-date. Is there some extra step I'm forgetting in order to make github happy?

@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
@randhid
Copy link
Member

randhid commented Dec 2, 2022

Agreed. The thermometer on a gyro isn't a priority. And if the manufacturer themselves have a published error, we shouldn't guess at the right scaling.

@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
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 59% 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% +1.43%
go.viam.com/rdk/components/camera/transformpipeline 78% -1.00%
go.viam.com/rdk/components/camera/videosource 55% 0.00%
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% 0.00%
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 63% 0.00%
go.viam.com/rdk/components/motor/gpiostepper 57% 0.00%
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.08%
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 68% -0.05%
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.00%
go.viam.com/rdk/robot/server 59% 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.00%
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% (19723 / 29943) 0.00%

@penguinland penguinland merged commit 7430a80 into viamrobotics:main Dec 2, 2022
@penguinland penguinland deleted the mpu6050 branch December 2, 2022 18:48
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.

3 participants