root / scout / power / src / power.cpp @ f40977a9
History | View | Annotate | Download (3.85 KB)
1 | dd4eb68c | Jeff Cooper | /**
|
---|---|---|---|
2 | * Copyright (c) 2011 Colony Project
|
||
3 | *
|
||
4 | * Permission is hereby granted, free of charge, to any person
|
||
5 | * obtaining a copy of this software and associated documentation
|
||
6 | * files (the "Software"), to deal in the Software without
|
||
7 | * restriction, including without limitation the rights to use,
|
||
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
9 | * copies of the Software, and to permit persons to whom the
|
||
10 | * Software is furnished to do so, subject to the following
|
||
11 | * conditions:
|
||
12 | *
|
||
13 | * The above copyright notice and this permission notice shall be
|
||
14 | * included in all copies or substantial portions of the Software.
|
||
15 | *
|
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||
23 | * OTHER DEALINGS IN THE SOFTWARE.
|
||
24 | c492be62 | Alex Zirbel | */
|
25 | dd4eb68c | Jeff Cooper | |
26 | /**
|
||
27 | * @file power.cpp
|
||
28 | * @brief Contains code to monitor and regulate power systems
|
||
29 | *
|
||
30 | * Implementation of power monitor and control
|
||
31 | *
|
||
32 | * @author Colony Project, CMU Robotics Club
|
||
33 | * @author Jeff Cooper
|
||
34 | **/
|
||
35 | |||
36 | #include "ros/ros.h" |
||
37 | #include "power.h" |
||
38 | #include <cstdlib> |
||
39 | |||
40 | /**
|
||
41 | * @defgroup power Power
|
||
42 | * @brief Functions for monitoring and regulating the power systems
|
||
43 | *
|
||
44 | * @{
|
||
45 | **/
|
||
46 | |||
47 | /* Power system state variables
|
||
48 | * updated by the AVR, used to respond to
|
||
49 | * power queries and send messages
|
||
50 | *
|
||
51 | */
|
||
52 | /** @todo Fix types: static */
|
||
53 | |||
54 | /** @TODO figure out if we can get things like the current draw from the AVR. */
|
||
55 | /** @TODO More generally, figure out how we get info from the AVR (avrbridge
|
||
56 | * node?) */
|
||
57 | |||
58 | uint32_t voltage; /**< the current voltage */
|
||
59 | uint32_t percentage; /**< current percentage of power remaining */
|
||
60 | uint32_t draw; /**< the current draw in mW */
|
||
61 | /** @TODO: figure out if these have to be uint8_t's to play nice with ROS */
|
||
62 | bool externalpower; /**< are we on external power? */ |
||
63 | bool warning; /**< is the battery reporting a warning state? */ |
||
64 | bool critical; /**< is the battery reporting a critical state? */ |
||
65 | |||
66 | /**
|
||
67 | * @brief Outputs current power state information
|
||
68 | *
|
||
69 | * Serves the service query_power by responding to service requests with the
|
||
70 | * state of the power system
|
||
71 | * @param req The request. There are no fields
|
||
72 | * @param res The response. The fields will be filled with values.
|
||
73 | */
|
||
74 | bool power_query(power::query_power::Request &req,
|
||
75 | power::query_power::Response &res) |
||
76 | { |
||
77 | res.voltage = voltage; |
||
78 | res.percentage = percentage; |
||
79 | res.draw = draw; |
||
80 | res.externalpower = externalpower; |
||
81 | res.warning = warning; |
||
82 | res.critical = critical; |
||
83 | |||
84 | ROS_DEBUG("Power speeds queried");
|
||
85 | return true; |
||
86 | } |
||
87 | |||
88 | |||
89 | 286daac2 | Jeff Cooper | /** @TODO: implement a function to send a message about the power state when
|
90 | * it's critical. can't do much with this until I have some way of reading the
|
||
91 | * power state from the AVR, I don't believe. */
|
||
92 | |||
93 | |||
94 | dd4eb68c | Jeff Cooper | /**
|
95 | * @brief Power driver. This is a ROS node that monitors and regulates the power
|
||
96 | * systems
|
||
97 | *
|
||
98 | * This is the main function for the power node. It is run when the node
|
||
99 | * starts. It advertises the query_power service.
|
||
100 | *
|
||
101 | * @param argc The number of command line arguments (should be 1)
|
||
102 | * @param argv The array of command line arguments
|
||
103 | **/
|
||
104 | int main(int argc, char **argv) |
||
105 | { |
||
106 | /* Initialize in ROS the motors driver node */
|
||
107 | ros::init(argc, argv, "power_driver");
|
||
108 | |||
109 | /* Advertise that this serves the query_motors service */
|
||
110 | ros::NodeHandle n; |
||
111 | ros::ServiceServer service = n.advertiseService("query_power",
|
||
112 | power_query); |
||
113 | |||
114 | /* Initialize hardware for motors */
|
||
115 | // Hardware init functions here
|
||
116 | |||
117 | ROS_INFO("Ready to set motors.");
|
||
118 | ros::spin(); |
||
119 | |||
120 | return 0; |
||
121 | } |
||
122 | |||
123 | /** @} **/ |