Statistics
| Branch: | Revision:

scoutos / scout / power / src / power.cpp @ 126fea96

History | View | Annotate | Download (3.86 KB)

1
/**
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
 */
25

    
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
 * @defgroup power Power
36
 * @brief Functions for monitoring and regulating the power systems
37
 *
38
 * @{
39
 **/
40

    
41
#include "ros/ros.h"
42
#include "power.h"
43
#include <cstdlib>
44

    
45
/* Power system state variables
46
 * updated by the AVR, used to respond to
47
 * power queries and send messages
48
 *
49
 */
50

    
51
/** @todo Fix types: static */
52

    
53
/** @TODO figure out if we can get things like the current draw from the AVR. */
54
/** @TODO More generally, figure out how we get info from the AVR (avrbridge
55
 * node?) */
56

    
57
uint32_t voltage; /**< the current voltage */
58
uint32_t percentage; /**< current percentage of power remaining */
59
uint32_t draw; /**< the current draw in mW */
60
/** @TODO: figure out if these have to be uint8_t's to play nice with ROS */
61
bool externalpower; /**< are we on external power? */
62
bool warning; /**< is the battery reporting a warning state? */
63
bool critical; /**< is the battery reporting a critical state? */
64

    
65
/**
66
 * @brief Outputs current power state information
67
 *
68
 * Serves the service query_power by responding to service requests with the
69
 * state of the power system
70
 * @param req The request. There are no fields
71
 * @param res The response. The fields will be filled with values.
72
 */
73
bool power_query(::messages::query_power::Request &req,
74
                 ::messages::query_power::Response &res)
75
{
76
    res.voltage = voltage;
77
    res.percentage = percentage;
78
    res.draw = draw;
79
    res.externalpower = externalpower;
80
    res.warning = warning;
81
    res.critical = critical;
82

    
83
    ROS_DEBUG("Power speeds queried");
84
    return true;
85
}
86

    
87

    
88
/** @TODO: implement a function to send a message about the power state when
89
 * it's critical. can't do much with this until I have some way of reading the
90
 * power state from the AVR, I don't believe. */
91

    
92

    
93
/**
94
 * @brief Power driver. This is a ROS node that monitors and regulates the power
95
 * systems
96
 *
97
 * This is the main function for the power node. It is run when the node
98
 * starts. It advertises the query_power service.
99
 * 
100
 * @param argc The number of command line arguments (should be 1)
101
 * @param argv The array of command line arguments
102
 **/
103
int main(int argc, char **argv)
104
{
105
    /* Initialize in ROS the motors driver node */
106
    ros::init(argc, argv, "power_driver");
107

    
108
    /* Advertise that this serves the query_motors service */
109
    ros::NodeHandle n;
110
    ros::ServiceServer service = n.advertiseService("query_power",
111
                                                    power_query);
112

    
113
    /* Initialize hardware for motors */
114
    // Hardware init functions here
115

    
116
    ROS_INFO("Ready to set motors.");
117
    ros::spin();
118

    
119
    return 0;
120
}
121

    
122
/** @} **/