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
30#include "sensors/SensorData.h"
31
32namespace Boardcore
33{
34
44
63
67typedef std::map<const LoadCellValuesEnum, std::string> LoadCellValues;
68static LoadCellValues loadCellValues = {
69 {SET_SETPOINT_1, "A"}, {SET_SETPOINT_2, "B"},
70 {SET_SETPOINT_3, "C"}, {GET_SETPOINT_1, "a"},
71 {GET_SETPOINT_2, "b"}, {GET_SETPOINT_3, "c"},
72 {GROSS_WEIGHT, "t"}, {NET_WEIGHT, "n"},
73 {PEAK_WEIGHT, "p"}, {RESET_TARE, "z"},
74 {COMMUTE_TO_NET, "NET"}, {COMMUTE_TO_GROSS, "GROSS"}};
75
80{
82 RECEPTION_ERROR, // contains '?'
83 EXECUTION_ERROR // contains '#'
84};
85
91{
92 bool valid = false;
93
94 MBLoadCellData() : LoadCellData{0, 0.0}, valid(false) {}
95
96 explicit MBLoadCellData(float data) : MBLoadCellData{0, data} {}
97
98 explicit MBLoadCellData(uint64_t loadTimestamp, float data)
99 : LoadCellData{loadTimestamp, data}, valid(true)
100 {
101 }
102
103 static std::string header() { return "loadTimestamp,weight\n"; }
104
105 void print(std::ostream& os) const
106 {
107 if (valid)
108 os << loadTimestamp / 1000000.0 << "," << load << "\n";
109 }
110};
111
116{
123
128 void updateValue(LoadCellValuesEnum val, float data)
129 {
130 switch (val)
131 {
132 case PEAK_WEIGHT:
134 break;
135 case GET_SETPOINT_1:
137 break;
138 case GET_SETPOINT_2:
140 break;
141 case GET_SETPOINT_3:
143 break;
144 default:
145 break;
146 }
147 }
148
152 void print() const
153 {
154 /*if (netWeight.valid)
155 TRACE("Net Weight : %f [Kg]\n", netWeight.load);
156
157 if (grossWeight.valid)
158 TRACE("Gross Weight : %f [Kg]\n", grossWeight.load);
159 */
160 if (peakWeight.valid)
161 TRACE("Peak Weight : %f [Kg]\n", peakWeight.load);
162
163 if (setpoint1.valid)
164 TRACE("Setpoint 1 : %f [Kg]\n", setpoint1.load);
165
166 if (setpoint2.valid)
167 TRACE("Setpoint 2 : %f [Kg]\n", setpoint2.load);
168
169 if (setpoint3.valid)
170 TRACE("Setpoint 3 : %f [Kg]\n", setpoint3.load);
171 }
172};
173
178{
179 char weight[6];
180 char CRLF[2];
181};
182
187{
188 char beginStr[1];
189 char T[1];
190 char weightT[6];
191 char P[1];
192 char weightP[6];
193 char endStr[1];
194 char ck[2];
195 char CR[1];
196};
197
202{
203 char beginStr[2] = "$";
204 char addr[3] = "01";
205 char value[7] = "";
206 char req[6];
207 char ck[3];
208 char CR[2] = "\r";
209
215 {
216 uint8_t checksum = 0;
217 std::string str;
218 str.append(addr);
219 str.append(value);
220 str.append(req);
221
222 for (unsigned int i = 0; i < str.length(); i++)
223 checksum ^= str[i];
224
225 sprintf(ck, "%x", checksum);
226 }
227
233 std::string to_string()
234 {
235 std::string str;
236 str.append(beginStr);
237 str.append(addr);
238 str.append(value);
239 str.append(req);
240 str.append(ck);
241 str.append(CR);
242 return str;
243 }
244};
245
246} // namespace Boardcore
#define TRACE(...)
Definition Debug.h:58
This file includes all the types the logdecoder script will decode.
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.
static std::string header()
MBLoadCellData(uint64_t loadTimestamp, float data)
void print(std::ostream &os) const
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.