-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (50 loc) · 1.75 KB
/
main.cpp
File metadata and controls
62 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Arduino.h>
#include <dronecan.h>
// set up your parameters here with default values. NODEID should be kept
std::vector<DroneCAN::parameter> custom_parameters = {
{ "NODEID", DroneCAN::INT, 100, 0, 127 },
{ "PARM_1", DroneCAN::REAL, 0.0f, 0.0f, 100.0f },
};
DroneCAN dronecan;
uint32_t looptime = 0;
void setup()
{
// the following block of code should always run first. Adjust it at your own peril!
app_setup();
IWatchdog.begin(2000000);
Serial.begin(115200);
dronecan.init(
custom_parameters,
"Beyond Robotix Node"
);
// end of important starting code
// an example of getting and setting parameters within the code
dronecan.setParameter("PARM_1", 50.0f);
Serial.print("PARM_1 value: ");
Serial.println(dronecan.getParameter("PARM_1"));
while (true)
{
const uint32_t now = millis();
// send our battery message at 10Hz
// Don't use delay() since we need to call dronecan.cycle() as much as possible
if (now - looptime > 100)
{
looptime = millis();
// collect MCU core temperature data
int32_t vref = __LL_ADC_CALC_VREFANALOG_VOLTAGE(analogRead(AVREF), LL_ADC_RESOLUTION_12B);
int32_t cpu_temp = __LL_ADC_CALC_TEMPERATURE(vref, analogRead(ATEMP), LL_ADC_RESOLUTION_12B);
// construct dronecan packet
uavcan_equipment_power_BatteryInfo pkt{};
pkt.voltage = analogRead(PA1);
pkt.current = analogRead(PA0);
pkt.temperature = cpu_temp;
sendUavcanMsg(dronecan.canard, pkt);
}
dronecan.cycle();
IWatchdog.reload();
}
}
void loop()
{
// Doesn't work coming from bootloader ? use while loop in setup
}