-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (56 loc) · 1.66 KB
/
main.cpp
File metadata and controls
71 lines (56 loc) · 1.66 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
63
64
65
66
67
68
69
70
71
/*
* Arduino DroneCAN API v1.3
* This is an example app using the INA libary from https://github.com/RobTillaart/INA239
* You'll need to download the library
* this code is untested, and is just for illustration on how you could use the library. Hopefully I can test it with the INA soon : )
*/
#include <Arduino.h>
#include <dronecan.h>
#include "INA239.h"
INA239 INA(5, &SPI);
std::vector<DroneCAN::parameter> custom_parameters = {
{"NODEID", DroneCAN::INT, 127, 0, 127}};
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
SPI.begin();
if (!INA.begin())
{
Serial.println("Could not connect. Fix and Reboot");
while (1)
;
}
// set your shunt resistance here
INA.setMaxCurrentShunt(10, 0.015);
while (true)
{
const uint32_t now = millis();
// send our battery message at 10Hz
if (now - looptime > 100)
{
looptime = millis();
// construct dronecan packet
uavcan_equipment_power_BatteryInfo pkt{};
pkt.voltage = INA.getBusVoltage();
pkt.current = INA.getMilliAmpere() / 1000;
pkt.temperature = INA.getTemperature();
sendUavcanMsg(dronecan.canard, pkt);
}
dronecan.cycle();
IWatchdog.reload();
}
}
void loop()
{
// Doesn't work coming from bootloader ? use while loop in setup
}