Statistics
| Branch: | Revision:

scoutos / scout / power / src / power.cpp @ 3a73516c

History | View | Annotate | Download (3.81 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
 * @defgroup power Power
31
 * @brief Functions for monitoring and regulating the power systems
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Jeff Cooper
35
 *
36
 * @{
37
 **/
38

    
39
#include "ros/ros.h"
40
#include "power.h"
41
#include <cstdlib>
42

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

    
49
/** @todo Fix types: static */
50

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

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

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

    
81
    ROS_DEBUG("Power speeds queried");
82
    return true;
83
}
84

    
85

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

    
90

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

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

    
111
    /* Initialize hardware for motors */
112
    // Hardware init functions here
113

    
114
    ROS_INFO("Ready to set motors.");
115
    ros::spin();
116

    
117
    return 0;
118
}
119

    
120
/** @} **/