generated from libhal/libhal-__device__
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,134 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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,93 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// 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 <cmath> | ||
|
||
#include <libhal-sensor/imu/icm20948.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
float compute_heading(float x, float y, float offset = 0.0) | ||
{ | ||
float angle = 360 - (atan2(y, x) * (180.0 / std::numbers::pi)); | ||
angle += offset; // Apply offset | ||
if (angle < 0) { | ||
angle += 360; | ||
} else if (angle >= 360) { | ||
angle -= 360; | ||
} | ||
return angle; | ||
} | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& i2c = *p_map.i2c.value(); | ||
|
||
hal::print(console, "icm Application Starting...\n\n"); | ||
hal::delay(clock, 200ms); | ||
hal::sensor::icm20948 icm_device(i2c); | ||
|
||
hal::delay(clock, 200ms); | ||
icm_device.init_mag(); | ||
hal::delay(clock, 100ms); | ||
|
||
icm_device.auto_offsets(); | ||
|
||
while (true) { | ||
auto accel = icm_device.read_acceleration(); | ||
hal::delay(clock, 10ms); | ||
|
||
auto gyro = icm_device.read_gyroscope(); | ||
hal::delay(clock, 10ms); | ||
|
||
auto temp = icm_device.read_temperature(); | ||
hal::delay(clock, 10ms); | ||
|
||
auto mag = icm_device.read_magnetometer(); | ||
hal::delay(clock, 10ms); | ||
|
||
hal::print(console, "\n\n================Reading IMU================\n"); | ||
|
||
hal::print<128>(console, | ||
"\n\nG-Accel Values: x = %fg, y = %fg, z = %fg", | ||
accel.x, | ||
accel.y, | ||
accel.z); | ||
|
||
hal::print<128>(console, | ||
"\n\nGyro Values: x = %f, y = %f, z = %f", | ||
gyro.x, | ||
gyro.y, | ||
gyro.z); | ||
|
||
hal::print<128>(console, "\n\nCurrent Temperature: %f°C", temp.temp); | ||
|
||
hal::print<128>(console, | ||
"\n\nMagnetometer Values: x = %f, y = %f, z = %f", | ||
mag.x, | ||
mag.y, | ||
mag.z); | ||
|
||
float heading = compute_heading(mag.x, mag.y, 0.0); | ||
hal::print<128>(console, "\n\nHeading: %f°", heading); | ||
hal::print(console, "\n\n===========================================\n"); | ||
} | ||
} |
This file contains 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,52 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// 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/multi/mpl3115a2.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& i2c = *p_map.i2c.value(); | ||
|
||
hal::print(console, "MPL3115A2 Demo Application Starting...\n"); | ||
hal::sensor::mpl3115a2 mpl_device(i2c); | ||
|
||
int8_t alt_offset = 0; | ||
mpl_device.set_altitude_offset(alt_offset); | ||
|
||
// Set sea level pressure to 30 Hg | ||
float slp = 101325; // Default is 101325 Pa | ||
mpl_device.set_sea_pressure(slp); | ||
|
||
while (true) { | ||
hal::delay(clock, 500ms); | ||
|
||
auto temperature = mpl_device.read_temperature().temperature; | ||
hal::print<42>(console, "Measured temperature = %f °C\n", temperature); | ||
|
||
auto pressure = mpl_device.read_pressure().pressure; | ||
hal::print<42>(console, "Measured pressure = %f Pa\n", pressure); | ||
|
||
auto altitude = mpl_device.read_altitude().altitude; | ||
hal::print<42>(console, "Measured altitude = %f m\n\n", altitude); | ||
} | ||
} |
This file contains 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,63 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// 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/imu/mpu6050.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& i2c = *p_map.i2c.value(); | ||
|
||
hal::print(console, "MPU6050 Application Starting...\n"); | ||
hal::sensor::mpu6050 mpu(i2c, 0x68); | ||
|
||
while (true) { | ||
hal::print( | ||
console, | ||
"Setting acceleration max scale to 2g (2 earth gravities)... \n"); | ||
|
||
mpu.configure_full_scale(hal::sensor::mpu6050::max_acceleration::g2); | ||
|
||
hal::print(console, "Reading acceleration... \n"); | ||
auto acceleration = mpu.read(); | ||
|
||
hal::print<64>(console, | ||
"Scale: 2g \t x = %fg, y = %fg, z = %fg \n", | ||
acceleration.x, | ||
acceleration.y, | ||
acceleration.z); | ||
|
||
hal::delay(clock, 500ms); | ||
|
||
hal::print( | ||
console, | ||
"Setting acceleration max scale to 4g (4 earth gravities)... \n"); | ||
|
||
mpu.configure_full_scale(hal::sensor::mpu6050::max_acceleration::g4); | ||
acceleration = mpu.read(); | ||
hal::print<64>(console, | ||
"Scale: 4g \t x = %fg, y = %fg, z = %fg \n\n", | ||
acceleration.x, | ||
acceleration.y, | ||
acceleration.z); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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.