Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / analog / src / analog.cpp @ 572adceb

History | View | Annotate | Download (2.9 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 analog.cpp
28
 * @brief Contains code to read analog data.
29
 *
30
 * Implementation of functions for analog use.
31
 *
32
 * @author Colony Project, CMU Robotics Club
33
 * @author Dev Gurjar
34
 **/
35

    
36
#include <ros/ros.h>
37

    
38
#include "analog.h"
39

    
40
/**
41
 * @defgroup analog Analog
42
 * @brief Functions for reading analog input
43
 *
44
 * @{
45
 **/
46

    
47
/* Analog state variables */
48
/** @todo Fix types: static */
49
unsigned int port; /**< The current port from which we are reading from. */
50

    
51
/**
52
 * @brief Outputs current analog data at a given port
53
 *
54
 * Serves the service query_analog by responding to service requests with the
55
 * speeds of the motors.
56
 * @param req The request. The only field is the units requested.
57
 * @param res The response. The fields will be filled with values.
58
 */
59
bool analog_query(analog::query_analog::Request &req,
60
                  analog::query_analog::Response &res)
61
{
62
    int port = req.port;
63
    res.sensor_data = get_sensor_data(port);
64

    
65
    ROS_DEBUG("Analog data queried");
66
    return true;
67
}
68

    
69
/* 
70
 * @brief 
71
 *
72
 * Given a port number, returns the analog data present at the port
73
 * 
74
 * @param port The port we want to read from
75
 */
76
unsigned int get_sensor_data(int port)
77
{
78
    ROS_DEBUG("Got Analog data from the sensor [Unimplemented]");
79
    return 0;
80
}
81

    
82
/**
83
 * @brief Analog driver. Provides an interface to read data from analog ports.
84
 */
85
int main(int argc, char **argv)
86
{
87
    /* Initialize in ROS the motors driver node */
88
    ros::init(argc, argv, "analog_driver");
89

    
90
    /* Advertise that this serves the query_analog service */
91
    ros::NodeHandle n;
92
    ros::ServiceServer service = n.advertiseService("query_analog",
93
                                                    analog_query);
94

    
95
    /* Initialize hardware for analog */
96

    
97
    // Hardware init functions here
98
    ros::spin();
99

    
100
    return 0;
101
}
102

    
103
/** @} **/