Skyward boardcore
Loading...
Searching...
No Matches
MBLoadCellData.h
Go to the documentation of this file.
1/* Copyright (c) 2021 Skyward Experimental Rocketry
2 * Author: Emilio Corigliano
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <utils/Debug.h>
26
27#include <cstdio>
28#include <map>
29#include <reflect.hpp>
30
31#include "sensors/SensorData.h"
32
33namespace Boardcore
34{
35
45
64
68typedef std::map<const LoadCellValuesEnum, std::string> LoadCellValues;
69static LoadCellValues loadCellValues = {
70 {SET_SETPOINT_1, "A"}, {SET_SETPOINT_2, "B"},
71 {SET_SETPOINT_3, "C"}, {GET_SETPOINT_1, "a"},
72 {GET_SETPOINT_2, "b"}, {GET_SETPOINT_3, "c"},
73 {GROSS_WEIGHT, "t"}, {NET_WEIGHT, "n"},
74 {PEAK_WEIGHT, "p"}, {RESET_TARE, "z"},
75 {COMMUTE_TO_NET, "NET"}, {COMMUTE_TO_GROSS, "GROSS"}};
76
81{
83 RECEPTION_ERROR, // contains '?'
84 EXECUTION_ERROR // contains '#'
85};
86
92{
93 bool valid = false;
94
95 MBLoadCellData() : LoadCellData{0, 0.0}, valid(false) {}
96
97 explicit MBLoadCellData(float data) : MBLoadCellData{0, data} {}
98
99 explicit MBLoadCellData(uint64_t loadTimestamp, float data)
100 : LoadCellData{loadTimestamp, data}, valid(true)
101 {
102 }
103
104 static constexpr auto reflect()
105 {
106 return STRUCT_DEF(MBLoadCellData,
107 EXTEND_DEF(LoadCellData) FIELD_DEF(valid));
108 }
109};
110
115{
122
127 void updateValue(LoadCellValuesEnum val, float data)
128 {
129 switch (val)
130 {
131 case PEAK_WEIGHT:
133 break;
134 case GET_SETPOINT_1:
136 break;
137 case GET_SETPOINT_2:
139 break;
140 case GET_SETPOINT_3:
142 break;
143 default:
144 break;
145 }
146 }
147
151 void print() const
152 {
153 /*if (netWeight.valid)
154 TRACE("Net Weight : %f [Kg]\n", netWeight.load);
155
156 if (grossWeight.valid)
157 TRACE("Gross Weight : %f [Kg]\n", grossWeight.load);
158 */
159 if (peakWeight.valid)
160 TRACE("Peak Weight : %f [Kg]\n", peakWeight.load);
161
162 if (setpoint1.valid)
163 TRACE("Setpoint 1 : %f [Kg]\n", setpoint1.load);
164
165 if (setpoint2.valid)
166 TRACE("Setpoint 2 : %f [Kg]\n", setpoint2.load);
167
168 if (setpoint3.valid)
169 TRACE("Setpoint 3 : %f [Kg]\n", setpoint3.load);
170 }
171};
172
177{
178 char weight[6];
179 char CRLF[2];
180};
181
186{
187 char beginStr[1];
188 char T[1];
189 char weightT[6];
190 char P[1];
191 char weightP[6];
192 char endStr[1];
193 char ck[2];
194 char CR[1];
195};
196
201{
202 char beginStr[2] = "$";
203 char addr[3] = "01";
204 char value[7] = "";
205 char req[6];
206 char ck[3];
207 char CR[2] = "\r";
208
214 {
215 uint8_t checksum = 0;
216 std::string str;
217 str.append(addr);
218 str.append(value);
219 str.append(req);
220
221 for (unsigned int i = 0; i < str.length(); i++)
222 checksum ^= str[i];
223
224 sprintf(ck, "%x", checksum);
225 }
226
232 std::string to_string()
233 {
234 std::string str;
235 str.append(beginStr);
236 str.append(addr);
237 str.append(value);
238 str.append(req);
239 str.append(ck);
240 str.append(CR);
241 return str;
242 }
243};
244
245} // namespace Boardcore
#define TRACE(...)
Definition Debug.h:58
Driver for the VN100S IMU.
ReturnsStates
Structure of the errors in the ASCII requests.
LoadCellModes
Enumeration of all the modes supported by the driver.
LoadCellValuesEnum
Enumeration of all the requests in ASCII mode.
std::map< const LoadCellValuesEnum, std::string > LoadCellValues
Type that maps the different requests to their keyword.
Structure that contains all the parameters for the request to be sent.
std::string to_string()
Transforms the request into a string to be sent over serial.
void setChecksum()
In base of the address and the request parameter calculates the checksum.
Structure of the output of the load cell in [continuous mode -> ModT].
Structure of the output of the load cell in [continuous mode -> ModTd].
Structure that stores a data value, with his timestamp and his validity.
MBLoadCellData(uint64_t loadTimestamp, float data)
static constexpr auto reflect()
Structure of the output of the load cell in [continuous mode -> ModT].
void updateValue(LoadCellValuesEnum val, float data)
Updates the correct value with the data passed. Also, memorizes the maximum and minimum value of the ...
void print() const
Prints the structure in a nice way.