Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FprimeZephyrReference/Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Imu/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver/")
20 changes: 1 addition & 19 deletions FprimeZephyrReference/Components/Imu/Imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ namespace Components {
// ----------------------------------------------------------------------

Imu ::Imu(const char* const compName) : ImuComponentBase(compName) {
// Initialize the LIS2MDL sensor
lis2mdl = device_get_binding("LIS2MDL");
FW_ASSERT(device_is_ready(lis2mdl));

// Initialize the LSM6DSO sensor
lsm6dso = DEVICE_DT_GET_ONE(st_lsm6dso);
FW_ASSERT(device_is_ready(lsm6dso));
Expand All @@ -38,13 +34,12 @@ void Imu ::run_handler(FwIndexType portNum, U32 context) {
// Fetch new data samples from the sensors
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_ACCEL_XYZ);
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_GYRO_XYZ);
sensor_sample_fetch_chan(lis2mdl, SENSOR_CHAN_MAGN_XYZ);
sensor_sample_fetch_chan(lsm6dso, SENSOR_CHAN_DIE_TEMP);

// Output sensor values via telemetry
this->tlmWrite_Acceleration(this->get_acceleration());
this->tlmWrite_AngularVelocity(this->get_angular_velocity());
this->tlmWrite_MagneticField(this->get_magnetic_field());
this->tlmWrite_MagneticField(this->readMagneticField_out(0));
this->tlmWrite_Temperature(this->get_temperature());
}

Expand Down Expand Up @@ -78,19 +73,6 @@ Components::Imu_AngularVelocity Imu ::get_angular_velocity() {
this->sensor_value_to_f64(z));
}

Components::Imu_MagneticField Imu ::get_magnetic_field() {
struct sensor_value x;
struct sensor_value y;
struct sensor_value z;

sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_X, &x);
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Y, &y);
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Z, &z);

return Components::Imu_MagneticField(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
this->sensor_value_to_f64(z));
}

F64 Imu ::get_temperature() {
struct sensor_value temp;

Expand Down
15 changes: 5 additions & 10 deletions FprimeZephyrReference/Components/Imu/Imu.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Components {
passive component Imu {
sync input port run: Svc.Sched

output port readMagneticField: MagneticFieldRead

@ Acceleration reading in m/s^2
struct Acceleration {
x: F64
Expand All @@ -13,6 +15,9 @@ module Components {
@ Telemetry channel for acceleration
telemetry Acceleration: Acceleration

@ Telemetry channel for magnetic field
telemetry MagneticField: MagneticField

@ Angular velocity reading in rad/s
struct AngularVelocity {
x: F64
Expand All @@ -23,16 +28,6 @@ module Components {
@ Telemetry channel for angular velocity
telemetry AngularVelocity: AngularVelocity

@ Magnetic field reading in gauss
struct MagneticField {
x: F64
y: F64
z: F64
}

@ Telemetry channel for magnetic field
telemetry MagneticField: MagneticField

@ Telemetry channel for temperature in degrees Celsius
telemetry Temperature: F64

Expand Down
6 changes: 0 additions & 6 deletions FprimeZephyrReference/Components/Imu/Imu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,13 @@ class Imu final : public ImuComponentBase {
//! Get the angular velocity reading from the IMU
Components::Imu_AngularVelocity get_angular_velocity();

//! Get the magnetic field reading from the IMU
Components::Imu_MagneticField get_magnetic_field();

//! Get the temperature reading from the IMU
F64 get_temperature();

// ----------------------------------------------------------------------
// Member variables
// ----------------------------------------------------------------------

//! Zephyr device stores the initialized LIS2MDL sensor
const struct device* lis2mdl;

//! Zephyr device stores the initialized LSM6DSO sensor
const struct device* lsm6dso;
};
Expand Down
36 changes: 36 additions & 0 deletions FprimeZephyrReference/Components/Lis2mdlDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
####
# F Prime CMakeLists.txt:
#
# SOURCES: list of source files (to be compiled)
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
# DEPENDS: list of libraries that this module depends on
#
# More information in the F´ CMake API documentation:
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
#
####

# Module names are derived from the path from the nearest project/library/framework
# root when not specifically overridden by the developer. i.e. The module defined by
# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`.

register_fprime_library(
AUTOCODER_INPUTS
"${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver.fpp"
SOURCES
"${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver.cpp"
# DEPENDS
# MyPackage_MyOtherModule
)

### Unit Tests ###
# register_fprime_ut(
# AUTOCODER_INPUTS
# "${CMAKE_CURRENT_LIST_DIR}/Lis2mdlDriver.fpp"
# SOURCES
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlDriverTestMain.cpp"
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/Lis2mdlDriverTester.cpp"
# DEPENDS
# STest # For rules-based testing
# UT_AUTO_HELPERS
# )
44 changes: 44 additions & 0 deletions FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// ======================================================================
// \title Lis2mdlDriver.cpp
// \author aychar
// \brief cpp file for Lis2mdlDriver component implementation class
// ======================================================================

#include "FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriver.hpp"

#include <Fw/Types/Assert.hpp>

namespace Components {

// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

Lis2mdlDriver ::Lis2mdlDriver(const char* const compName) : Lis2mdlDriverComponentBase(compName) {
lis2mdl = device_get_binding("LIS2MDL");
FW_ASSERT(device_is_ready(lis2mdl));
}

Lis2mdlDriver ::~Lis2mdlDriver() {}

F64 Lis2mdlDriver ::sensor_value_to_f64(const struct sensor_value& val) {
return val.val1 + val.val2 / 1000000.0f;
}

Components::MagneticField Lis2mdlDriver ::getMagneticField_handler(FwIndexType portNum) {
// Fetch new data sample from sensors
sensor_sample_fetch_chan(lis2mdl, SENSOR_CHAN_MAGN_XYZ);

struct sensor_value x;
struct sensor_value y;
struct sensor_value z;

sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_X, &x);
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Y, &y);
sensor_channel_get(lis2mdl, SENSOR_CHAN_MAGN_Z, &z);

return Components::MagneticField(this->sensor_value_to_f64(x), this->sensor_value_to_f64(y),
this->sensor_value_to_f64(z));
}

} // namespace Components
24 changes: 24 additions & 0 deletions FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriver.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Components {
@ Magnetic field reading in gauss
struct MagneticField {
x: F64
y: F64
z: F64
}

# Port definitions
port MagneticFieldRead -> MagneticField

@ Component for F Prime FSW framework.
passive component Lis2mdlDriver {

sync input port getMagneticField: MagneticFieldRead

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
###############################################################################
@ Port for requesting the current time
time get port timeCaller

}
}
52 changes: 52 additions & 0 deletions FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ======================================================================
// \title Lis2mdlDriver.hpp
// \author aychar
// \brief hpp file for Lis2mdlDriver component implementation class
// ======================================================================

#ifndef Components_Lis2mdlDriver_HPP
#define Components_Lis2mdlDriver_HPP

#include "FprimeZephyrReference/Components/Lis2mdlDriver/Lis2mdlDriverComponentAc.hpp"

#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/kernel.h>

namespace Components {

class Lis2mdlDriver final : public Lis2mdlDriverComponentBase {
public:
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

//! Construct Lis2mdlDriver object
Lis2mdlDriver(const char* const compName //!< The component name
);

//! Destroy Lis2mdlDriver object
~Lis2mdlDriver();

private:
//! Handler implementation
MagneticField getMagneticField_handler(FwIndexType portNum) override;

// ----------------------------------------------------------------------
// Helper methods
// ----------------------------------------------------------------------

//! Convert a Zephyr sensor_value to an Fprime F64
F64 sensor_value_to_f64(const struct sensor_value& val);

// ----------------------------------------------------------------------
// Member variables
// ----------------------------------------------------------------------

//! Zephyr device stores the initialized LIS2MDL sensor
const struct device* lis2mdl;
};

} // namespace Components

#endif
66 changes: 66 additions & 0 deletions FprimeZephyrReference/Components/Lis2mdlDriver/docs/sdd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Components::Lis2mdlDriver

Component for F Prime FSW framework.

## Usage Examples
Add usage examples here

### Diagrams
Add diagrams here

### Typical Usage
And the typical usage of the component here

## Class Diagram
Add a class diagram here

## Port Descriptions
| Name | Description |
|---|---|
|---|---|

## Component States
Add component states in the chart below
| Name | Description |
|---|---|
|---|---|

## Sequence Diagrams
Add sequence diagrams here

## Parameters
| Name | Description |
|---|---|
|---|---|

## Commands
| Name | Description |
|---|---|
|---|---|

## Events
| Name | Description |
|---|---|
|---|---|

## Telemetry
| Name | Description |
|---|---|
|---|---|

## Unit Tests
Add unit test descriptions in the chart below
| Name | Description | Output | Coverage |
|---|---|---|---|
|---|---|---|---|

## Requirements
Add requirements in the chart below
| Name | Description | Validation |
|---|---|---|
|---|---|---|

## Change Log
| Date | Description |
|---|---|
|---| Initial Draft |
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ telemetry packets ReferenceDeploymentPackets {
ReferenceDeployment.imu.MagneticField
}


} omit {
CdhCore.cmdDisp.CommandErrors
# Only has one library, no custom versions
Expand Down
2 changes: 2 additions & 0 deletions FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ module ReferenceDeployment {
instance watchdog: Components.Watchdog base id 0x10016000

instance imu: Components.Imu base id 0x10017000

instance lis2mdlDriver: Components.Lis2mdlDriver base id 0x10018000
}
5 changes: 5 additions & 0 deletions FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module ReferenceDeployment {
instance watchdog
instance prmDb
instance imu
instance lis2mdlDriver

# ----------------------------------------------------------------------
# Pattern graph specifiers
Expand Down Expand Up @@ -100,6 +101,10 @@ module ReferenceDeployment {
watchdog.gpioSet -> gpioDriver.gpioWrite
}

connections Imu {
imu.readMagneticField -> lis2mdlDriver.getMagneticField
}

connections ReferenceDeployment {

}
Expand Down