Skip to content

Commit 8478ca1

Browse files
asiemsenineskhounateinactionSaidi AdamsMikefly123
authored
Create lsm6dso driver component & implementation (#17)
* Update README.md * Create lmsd6dsoDriver component * create ports for sensor reading output * fix port naming issue * Use custom board definition * Remove commented config * Moving prj.conf sensors to board definition * Add d board * Try referencing c definitions in d board * Making a common v5 board definition * Fix readme * Minor Makefile, Readme and cmake presets fixes * change lsm6dso internal structs to carry F64 and added output ports to imu * removed lmsdso init from imu constructor * remove old sensor reading from imu * add lms6dso driver to topology * change base id to allow for lis2mdl driver * remove line endings * add channel retrieval during sensor data * Ensure submodules are downloaded before venv is created * Fix infinit submodule make target recursion... --------- Co-authored-by: ineskhou <[email protected]> Co-authored-by: Nate Gay <[email protected]> Co-authored-by: Nate Gay <[email protected]> Co-authored-by: Saidi Adams <[email protected]> Co-authored-by: Michael Pham <[email protected]>
1 parent e44fa63 commit 8478ca1

28 files changed

+603
-184
lines changed

CMakePresets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
{
44
"binaryDir": "${sourceDir}/build-fprime-automatic-zephyr",
55
"cacheVariables": {
6-
"BOARD": "teensy41",
6+
"BOARD": "proves_flight_control_board_v5c/rp2350a/m33",
77
"CMAKE_BUILD_TYPE": "Release",
88
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
99
},
1010
"description": "F\u00b4 release build using local fprime-venv",
11-
"displayName": "F\u00b4 Zephyr (teensy41)",
11+
"displayName": "F\u00b4 FPrime Zephyr PROVES",
1212
"environment": {
1313
"PATH": "$env{VIRTUAL_ENV}/bin:$penv{PATH}",
1414
"VIRTUAL_ENV": "${fileDir}/fprime-venv"
1515
},
1616
"generator": "Ninja",
17-
"name": "fprime-zephyr-teensy41",
17+
"name": "fprime-zephyr-proves",
1818
"toolchainFile": "${fileDir}/lib/fprime-zephyr/cmake/toolchain/zephyr.cmake"
1919
}
2020
],

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
44
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
55
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Imu/")
6+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/lms6dsoDriver/")
67
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver/")

FprimeZephyrReference/Components/Imu/Imu.cpp

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,7 @@ namespace Components {
1313
// Component construction and destruction
1414
// ----------------------------------------------------------------------
1515

16-
Imu ::Imu(const char* const compName) : ImuComponentBase(compName) {
17-
// Initialize the LSM6DSO sensor
18-
lsm6dso = DEVICE_DT_GET_ONE(st_lsm6dso);
19-
FW_ASSERT(device_is_ready(lsm6dso));
20-
21-
// Configure the LSM6DSO sensor
22-
struct sensor_value odr = {.val1 = 12, .val2 = 500000}; // 12.5 Hz
23-
FW_ASSERT(sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &odr) == 0);
24-
FW_ASSERT(sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &odr) == 0);
25-
}
16+
Imu ::Imu(const char* const compName) : ImuComponentBase(compName) {}
2617

2718
Imu ::~Imu() {}
2819

@@ -31,53 +22,10 @@ Imu ::~Imu() {}
3122
// ----------------------------------------------------------------------
3223

3324
void Imu ::run_handler(FwIndexType portNum, U32 context) {
34-
// Fetch new data samples from the sensors
35-
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_ACCEL_XYZ);
36-
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_GYRO_XYZ);
37-
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_DIE_TEMP);
38-
39-
// Output sensor values via telemetry
40-
this->tlmWrite_Acceleration(this->get_acceleration());
41-
this->tlmWrite_AngularVelocity(this->get_angular_velocity());
25+
this->tlmWrite_Acceleration(this->readAcceleration_out(0));
26+
this->tlmWrite_AngularVelocity(this->readAngularVelocity_out(0));
4227
this->tlmWrite_MagneticField(this->readMagneticField_out(0));
43-
this->tlmWrite_Temperature(this->get_temperature());
44-
}
45-
46-
F64 Imu ::sensor_value_to_f64(const struct sensor_value& val) {
47-
return val.val1 + val.val2 / 1000000.0f;
48-
}
49-
50-
Components::Imu_Acceleration Imu ::get_acceleration() {
51-
struct sensor_value x;
52-
struct sensor_value y;
53-
struct sensor_value z;
54-
55-
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_X, &x);
56-
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_Y, &y);
57-
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_Z, &z);
58-
59-
return Components::Imu_Acceleration(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
60-
this->sensor_value_to_f64(z));
61-
}
62-
63-
Components::Imu_AngularVelocity Imu ::get_angular_velocity() {
64-
struct sensor_value x;
65-
struct sensor_value y;
66-
struct sensor_value z;
67-
68-
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_X, &x);
69-
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_Y, &y);
70-
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_Z, &z);
71-
72-
return Components::Imu_AngularVelocity(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
73-
this->sensor_value_to_f64(z));
28+
this->tlmWrite_Temperature(this->readTemperature_out(0));
7429
}
7530

76-
F64 Imu ::get_temperature() {
77-
struct sensor_value temp;
78-
79-
sensor_channel_get(lsm6dso, SENSOR_CHAN_DIE_TEMP, &temp);
80-
81-
return this->sensor_value_to_f64(temp);
82-
}
8331
} // namespace Components

FprimeZephyrReference/Components/Imu/Imu.fpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,20 @@ module Components {
33
passive component Imu {
44
sync input port run: Svc.Sched
55

6+
output port readAcceleration: AccelerationRead
7+
output port readAngularVelocity: AngularVelocityRead
68
output port readMagneticField: MagneticFieldRead
9+
output port readTemperature: TemperatureRead
710

8-
@ Acceleration reading in m/s^2
9-
struct Acceleration {
10-
x: F64
11-
y: F64
12-
z: F64
13-
}
11+
@Telemetry channel for angular velocity
12+
telemetry AngularVelocity: AngularVelocity
1413

15-
@ Telemetry channel for acceleration
14+
@ Telemetry channel for Acceleration
1615
telemetry Acceleration: Acceleration
1716

1817
@ Telemetry channel for magnetic field
1918
telemetry MagneticField: MagneticField
2019

21-
@ Angular velocity reading in rad/s
22-
struct AngularVelocity {
23-
x: F64
24-
y: F64
25-
z: F64
26-
}
27-
28-
@ Telemetry channel for angular velocity
29-
telemetry AngularVelocity: AngularVelocity
30-
3120
@ Telemetry channel for temperature in degrees Celsius
3221
telemetry Temperature: F64
3322

FprimeZephyrReference/Components/Imu/Imu.hpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
#include "FprimeZephyrReference/Components/Imu/ImuComponentAc.hpp"
1010

11-
#include <zephyr/device.h>
12-
#include <zephyr/drivers/sensor.h>
13-
#include <zephyr/kernel.h>
14-
1511
namespace Components {
1612

1713
class Imu final : public ImuComponentBase {
@@ -35,33 +31,6 @@ class Imu final : public ImuComponentBase {
3531
void run_handler(FwIndexType portNum, //!< The port number
3632
U32 context //!< The call order
3733
) override;
38-
39-
// ----------------------------------------------------------------------
40-
// Helper methods
41-
// ----------------------------------------------------------------------
42-
43-
//! Convert a Zephyr sensor_value to an Fprime F64
44-
F64 sensor_value_to_f64(const struct sensor_value& val);
45-
46-
// ----------------------------------------------------------------------
47-
// IMU access methods
48-
// ----------------------------------------------------------------------
49-
50-
//! Get the acceleration reading from the IMU
51-
Components::Imu_Acceleration get_acceleration();
52-
53-
//! Get the angular velocity reading from the IMU
54-
Components::Imu_AngularVelocity get_angular_velocity();
55-
56-
//! Get the temperature reading from the IMU
57-
F64 get_temperature();
58-
59-
// ----------------------------------------------------------------------
60-
// Member variables
61-
// ----------------------------------------------------------------------
62-
63-
//! Zephyr device stores the initialized LSM6DSO sensor
64-
const struct device* lsm6dso;
6534
};
6635

6736
} // namespace Components
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
####
2+
# F Prime CMakeLists.txt:
3+
#
4+
# SOURCES: list of source files (to be compiled)
5+
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
6+
# DEPENDS: list of libraries that this module depends on
7+
#
8+
# More information in the F´ CMake API documentation:
9+
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
10+
#
11+
####
12+
13+
# Module names are derived from the path from the nearest project/library/framework
14+
# root when not specifically overridden by the developer. i.e. The module defined by
15+
# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`.
16+
17+
register_fprime_library(
18+
AUTOCODER_INPUTS
19+
"${CMAKE_CURRENT_LIST_DIR}/lms6dsoDriver.fpp"
20+
SOURCES
21+
"${CMAKE_CURRENT_LIST_DIR}/lms6dsoDriver.cpp"
22+
# DEPENDS
23+
# MyPackage_MyOtherModule
24+
)
25+
26+
### Unit Tests ###
27+
# register_fprime_ut(
28+
# AUTOCODER_INPUTS
29+
# "${CMAKE_CURRENT_LIST_DIR}/lms6dsoDriver.fpp"
30+
# SOURCES
31+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/lms6dsoDriverTestMain.cpp"
32+
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/lms6dsoDriverTester.cpp"
33+
# DEPENDS
34+
# STest # For rules-based testing
35+
# UT_AUTO_HELPERS
36+
# )
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Components::lms6dsoDriver
2+
3+
Initialize and control operation of the lms6dso device
4+
5+
## Usage Examples
6+
Add usage examples here
7+
8+
### Diagrams
9+
Add diagrams here
10+
11+
### Typical Usage
12+
And the typical usage of the component here
13+
14+
## Class Diagram
15+
Add a class diagram here
16+
17+
## Port Descriptions
18+
| Name | Description |
19+
|---|---|
20+
|---|---|
21+
22+
## Component States
23+
Add component states in the chart below
24+
| Name | Description |
25+
|---|---|
26+
|---|---|
27+
28+
## Sequence Diagrams
29+
Add sequence diagrams here
30+
31+
## Parameters
32+
| Name | Description |
33+
|---|---|
34+
|---|---|
35+
36+
## Commands
37+
| Name | Description |
38+
|---|---|
39+
|---|---|
40+
41+
## Events
42+
| Name | Description |
43+
|---|---|
44+
|---|---|
45+
46+
## Telemetry
47+
| Name | Description |
48+
|---|---|
49+
|---|---|
50+
51+
## Unit Tests
52+
Add unit test descriptions in the chart below
53+
| Name | Description | Output | Coverage |
54+
|---|---|---|---|
55+
|---|---|---|---|
56+
57+
## Requirements
58+
Add requirements in the chart below
59+
| Name | Description | Validation |
60+
|---|---|---|
61+
|---|---|---|
62+
63+
## Change Log
64+
| Date | Description |
65+
|---|---|
66+
|---| Initial Draft |
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ======================================================================
2+
// \title lms6dsoDriver.cpp
3+
// \author aaron
4+
// \brief cpp file for lms6dsoDriver component implementation class
5+
// ======================================================================
6+
7+
#include "FprimeZephyrReference/Components/lms6dsoDriver/lms6dsoDriver.hpp"
8+
9+
namespace Components {
10+
11+
// ----------------------------------------------------------------------
12+
// Component construction and destruction
13+
// ----------------------------------------------------------------------
14+
15+
lms6dsoDriver ::lms6dsoDriver(const char* const compName) : lms6dsoDriverComponentBase(compName) {
16+
// Initialize the LSM6DSO sensor
17+
lsm6dso = DEVICE_DT_GET_ONE(st_lsm6dso);
18+
FW_ASSERT(device_is_ready(lsm6dso));
19+
// Configure the LSM6DSO sensor
20+
struct sensor_value odr = {.val1 = 12, .val2 = 500000}; // 12.5 Hz
21+
sensor_attr_set(lsm6dso, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &odr);
22+
sensor_attr_set(lsm6dso, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &odr);
23+
}
24+
25+
lms6dsoDriver ::~lms6dsoDriver() {}
26+
27+
// ----------------------------------------------------------------------
28+
// Handler implementations for typed input ports
29+
// ----------------------------------------------------------------------
30+
31+
Components::Acceleration lms6dsoDriver::getAcceleration_handler(FwIndexType portNum) {
32+
struct sensor_value x;
33+
struct sensor_value y;
34+
struct sensor_value z;
35+
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_ACCEL_XYZ);
36+
37+
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_X, &x);
38+
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_Y, &y);
39+
sensor_channel_get(lsm6dso, SENSOR_CHAN_ACCEL_Z, &z);
40+
41+
return Components::Acceleration(this->sensor_value_to_f64(x),this->sensor_value_to_f64(y), this->sensor_value_to_f64(z));
42+
}
43+
44+
Components::AngularVelocity lms6dsoDriver::getAngularVelocity_handler(FwIndexType portNum) {
45+
struct sensor_value x;
46+
struct sensor_value y;
47+
struct sensor_value z;
48+
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_GYRO_XYZ);
49+
50+
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_X, &x);
51+
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_Y, &y);
52+
sensor_channel_get(lsm6dso, SENSOR_CHAN_GYRO_Z, &z);
53+
54+
return Components::AngularVelocity(this->sensor_value_to_f64(x),this->sensor_value_to_f64(y), this->sensor_value_to_f64(z));
55+
}
56+
57+
58+
F64 lms6dsoDriver::getTemperature_handler(FwIndexType portNum) {
59+
struct sensor_value temp;
60+
61+
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_DIE_TEMP);
62+
sensor_channel_get(lsm6dso, SENSOR_CHAN_DIE_TEMP, &temp);
63+
64+
return this->sensor_value_to_f64(temp);
65+
}
66+
67+
F64 lms6dsoDriver::sensor_value_to_f64(const struct sensor_value& val) {
68+
return val.val1 + val.val2 / 1000000.0f;
69+
}
70+
71+
} // namespace Components

0 commit comments

Comments
 (0)