-
Notifications
You must be signed in to change notification settings - Fork 5
✨(minor) Add AS5600 magnetic rotary encoder #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3cebce9
start work on as5600
MaliaLabor 0acc7e4
add more functions
MaliaLabor 88b6789
change functions to use degrees and tested
MaliaLabor 4f61294
comments and cleanup
MaliaLabor 7f3bc44
add clamps to angle functions
MaliaLabor c4c9a1a
remove burn stuff
MaliaLabor 8c1c456
working through change requests
MaliaLabor 12a2675
finish up change requests
MaliaLabor e6a853d
add remaining docs
MaliaLabor 458962e
fix build error
MaliaLabor fda4e88
Refactor power mode enum and improve comments
kammce 4a3bf4b
Refactor comments in as5600.hpp for clarity
kammce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright 2026 Malia Labor and the libhal contributors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <libhal-sensor/as5600.hpp> | ||
| #include <libhal-util/serial.hpp> | ||
| #include <libhal-util/steady_clock.hpp> | ||
|
|
||
| #include <resource_list.hpp> | ||
|
|
||
| void application() | ||
| { | ||
| using namespace std::chrono_literals; | ||
| using namespace hal::literals; | ||
|
|
||
| auto const clock = resources::clock(); | ||
| auto const console = resources::console(); | ||
| auto const i2c = resources::i2c(); | ||
|
|
||
| hal::print(*console, "AS5600 Application Starting...\n"); | ||
| hal::sensor::as5600 hall_sensor(i2c); | ||
|
|
||
| auto magnet_status = hall_sensor.magnet_status(); | ||
| if (magnet_status.detected) { | ||
| hal::print(*console, "Magnet detected\n"); | ||
| } | ||
| auto const start_angle = hall_sensor.start_angle(); | ||
| auto const stop_angle = hall_sensor.stop_angle(); | ||
| auto const angular_range = hall_sensor.angular_range(); | ||
| auto const power_mode = hall_sensor.power_mode(); | ||
| auto const hysteresis = hall_sensor.hysteresis(); | ||
| bool const watchdog_enabled = hall_sensor.watchdog_enabled(); | ||
|
|
||
| auto const agc = hall_sensor.auto_gain_control(); | ||
| auto const mag = hall_sensor.magnitude(); | ||
|
|
||
| hal::print<32>(*console, "Start angle: %.2f \n", start_angle); | ||
| hal::print<32>(*console, "Stop angle: %.2f \n", stop_angle); | ||
| hal::print<32>(*console, "Max Angle: %.2f \n", angular_range); | ||
| hal::print<32>(*console, "Power Mode: %d \n", power_mode); | ||
| hal::print<32>(*console, "Hysteresis: %d \n", hysteresis); | ||
| hal::print<32>(*console, "WD: %d \n", watchdog_enabled); | ||
| hal::print<32>(*console, "AGC: %d \n", agc); | ||
| hal::print<32>(*console, "Magnitude: %d \n", mag); | ||
|
|
||
| while (true) { | ||
| magnet_status = hall_sensor.magnet_status(); | ||
| if (magnet_status.detected) { | ||
| auto raw_angle = hall_sensor.raw_angle(); | ||
| auto angle = hall_sensor.angle(); | ||
|
|
||
| hal::print<64>(*console, "Raw Angle: %.2f ", raw_angle); | ||
| hal::print<64>(*console, "Angle: %.2f \n", angle); | ||
| } | ||
| hal::delay(*clock, 500ms); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.