Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Boardcore
Commits
e44e4ddb
Commit
e44e4ddb
authored
11 months ago
by
Davide Mor
Browse files
Options
Downloads
Patches
Plain Diff
[RIG] Added RIG analog sensors
parent
86553ba2
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!272
[RIG] Added RIG analog sensors
Pipeline
#8982
canceled
11 months ago
Stage: lint
Stage: build
Stage: test
Changes
2
Pipelines
5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/sensors/analog/TrafagPressureSensor.h
+88
-0
88 additions, 0 deletions
src/shared/sensors/analog/TrafagPressureSensor.h
src/shared/sensors/analog/TwoPointAnalogLoadCell.h
+99
-0
99 additions, 0 deletions
src/shared/sensors/analog/TwoPointAnalogLoadCell.h
with
187 additions
and
0 deletions
src/shared/sensors/analog/TrafagPressureSensor.h
0 → 100644
+
88
−
0
View file @
e44e4ddb
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Authors: Davide Mor
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include
<sensors/Sensor.h>
#include
<sensors/SensorData.h>
#include
<functional>
namespace
Boardcore
{
/**
* @brief Sensor class for a Trafag pressure sensor.
*/
class
TrafagPressureSensor
:
public
Sensor
<
PressureData
>
{
public:
/**
* @brief Construct a TrafagPressureSensor.
*
* @param getVoltage lambda to retrieve current voltage.
* @param shuntResistance shunt resistance value.
* @param maxPressure maximum pressure of this sensor.
* @param minCurrent current at the 0 pressure point.
* @param maxCurrent current at the maximum pressure point.
*/
TrafagPressureSensor
(
std
::
function
<
ADCData
()
>
getVoltage
,
float
shuntResistance
,
float
maxPressure
,
float
minCurrent
=
4
,
float
maxCurrent
=
20
)
:
getVoltage
{
getVoltage
},
shuntResistance
{
shuntResistance
},
maxPressure
{
maxPressure
},
minCurrent
{
minCurrent
},
maxCurrent
{
maxCurrent
}
{
}
bool
init
()
override
{
return
true
;
}
bool
selfTest
()
override
{
return
true
;
}
private
:
PressureData
sampleImpl
()
override
{
auto
voltage
=
getVoltage
();
return
{
voltage
.
voltageTimestamp
,
voltageToPressure
(
voltage
.
voltage
)};
}
float
voltageToPressure
(
float
voltage
)
{
// First convert voltage to current
float
current
=
(
voltage
/
shuntResistance
)
*
1000.0
f
;
// Convert to a value between 0 and 1
float
value
=
(
current
-
minCurrent
)
/
(
maxCurrent
-
minCurrent
);
// Scale from 0 to maxPressure
return
value
*
maxPressure
;
}
std
::
function
<
ADCData
()
>
getVoltage
;
const
float
shuntResistance
;
const
float
maxPressure
;
const
float
minCurrent
;
const
float
maxCurrent
;
};
}
// namespace Boardcore
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/shared/sensors/analog/TwoPointAnalogLoadCell.h
0 → 100644
+
99
−
0
View file @
e44e4ddb
/* Copyright (c) 2024 Skyward Experimental Rocketry
* Authors: Davide Mor
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include
<sensors/Sensor.h>
#include
<sensors/SensorData.h>
#include
<functional>
namespace
Boardcore
{
/**
* @brief Sensor class for a two point calibrated load cell.
*/
class
TwoPointAnalogLoadCell
:
public
Sensor
<
LoadCellData
>
{
public:
/**
* @brief Construct a TwoPointAnalogLoadCell.
*
* @param getVoltage lambda to retrieve current voltage.
* @param p0Voltage voltage of point 0.
* @param p0Mass mass of point 0.
* @param p1Voltage voltage of point 1.
* @param p1Mass mass of point 1.
*/
TwoPointAnalogLoadCell
(
std
::
function
<
ADCData
()
>
getVoltage
,
float
p0Voltage
,
float
p0Mass
,
float
p1Voltage
,
float
p1Mass
)
:
getVoltage
{
getVoltage
},
staticScale
{(
p1Mass
-
p0Mass
)
/
(
p1Voltage
-
p0Voltage
)},
staticOffset
{
p0Mass
-
staticScale
*
p0Voltage
}
{
}
bool
init
()
override
{
return
true
;
}
bool
selfTest
()
override
{
return
true
;
}
/**
* @brief Set the current load cell offset. Ignores any previous offsets.
*/
void
setOffset
(
float
value
)
{
miosix
::
Lock
<
miosix
::
FastMutex
>
lock
{
offsetMutex
};
dynamicOffset
=
value
;
}
/**
* @brief Update the current load cell offset. Adds the new value to the old
* offset.
*/
void
updateOffset
(
float
value
)
{
miosix
::
Lock
<
miosix
::
FastMutex
>
lock
{
offsetMutex
};
dynamicOffset
+=
value
;
}
private
:
LoadCellData
sampleImpl
()
override
{
auto
voltage
=
getVoltage
();
auto
mass
=
-
(
voltage
.
voltage
*
staticScale
+
staticOffset
);
miosix
::
Lock
<
miosix
::
FastMutex
>
lock
{
offsetMutex
};
return
{
voltage
.
voltageTimestamp
,
mass
-
dynamicOffset
};
}
std
::
function
<
ADCData
()
>
getVoltage
;
// std::atomic<float> does not support +=
miosix
::
FastMutex
offsetMutex
;
float
dynamicOffset
=
0.0
f
;
const
float
staticScale
;
const
float
staticOffset
;
};
}
// namespace Boardcore
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment