-
Notifications
You must be signed in to change notification settings - Fork 2
/
power_regulator_demo.cpp
88 lines (74 loc) · 3.09 KB
/
power_regulator_demo.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file power_regulator_demo.cpp
* @brief Weston Robot Power Regulator V2 API usage demo
* @date 02-04-2024
*
* Demo showing the Weston Robot Power Regulator V2 API.
*
* @copyright Copyright (c) 2024 Weston Robot Pte. Ltd.
*/
#include <unistd.h>
#include <thread>
#include <chrono>
#include <iostream>
#include "wrp_sdk/peripheral/power_regulator_v2.hpp"
using namespace westonrobot;
void PowerRegulatorStateCallback(
const PowerRegulatorInterface::DeviceState &state) {
std::cout << "Input voltage: " << state.input_voltage
<< ", temperature: " << state.temperature
<< ", fan-speed: " << state.fan_speed << std::endl;
std::cout << "[19V]: " << std::boolalpha
<< state.channels.at(PowerRegulatorV2::kChannel19V).enabled
<< std::hex << ", voltage: "
<< state.channels.at(PowerRegulatorV2::kChannel19V).voltage
<< ", current: "
<< state.channels.at(PowerRegulatorV2::kChannel19V).current
<< std::endl;
std::cout << "[12V]: " << std::boolalpha
<< state.channels.at(PowerRegulatorV2::kChannel12V).enabled
<< std::hex << ", voltage: "
<< state.channels.at(PowerRegulatorV2::kChannel12V).voltage
<< ", current: "
<< state.channels.at(PowerRegulatorV2::kChannel12V).current
<< std::endl;
std::cout << "[12Vi]: " << std::boolalpha
<< state.channels.at(PowerRegulatorV2::kChannel12Vi).enabled
<< std::hex << ", voltage: "
<< state.channels.at(PowerRegulatorV2::kChannel12Vi).voltage
<< ", current: "
<< state.channels.at(PowerRegulatorV2::kChannel12Vi).current
<< std::endl;
std::cout << "[5Vi]: " << std::boolalpha
<< state.channels.at(PowerRegulatorV2::kChannel5Vi).enabled
<< std::hex << ", voltage: "
<< state.channels.at(PowerRegulatorV2::kChannel5Vi).voltage
<< ", current: "
<< state.channels.at(PowerRegulatorV2::kChannel5Vi).current
<< std::endl;
std::cout << "---------------" << std::endl;
}
int main(int argc, char *argv[]) {
std::string device_path = "can0";
if (argc > 1) device_path = argv[1];
PowerRegulatorV2 regulator;
regulator.SetDataReceivedCallback(PowerRegulatorStateCallback);
regulator.Connect(device_path);
// start 19V channel first
regulator.SetChannelState(PowerRegulatorV2::kChannel19V, true);
std::this_thread::sleep_for(std::chrono::seconds(2));
// start 12V channel after 2s
regulator.SetChannelState(PowerRegulatorV2::kChannel12V, true);
std::this_thread::sleep_for(std::chrono::seconds(2));
// start 12V isolated channel after another 2s
regulator.SetChannelState(PowerRegulatorV2::kChannel12Vi, true);
std::this_thread::sleep_for(std::chrono::seconds(2));
// start 5V isolated channel after another 2s
regulator.SetChannelState(PowerRegulatorV2::kChannel5Vi, true);
std::this_thread::sleep_for(std::chrono::seconds(2));
while (regulator.IsOkay()) {
// do other work, while listening to state feedback via callback
sleep(5);
}
return 0;
}