root / scout / analog / src / analog.cpp @ 8e7baefc
History | View | Annotate | Download (3.27 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 |
#include "analog.h" |
38 |
//#include "libscout/src/constants.h"
|
39 |
#include <cstdlib> |
40 |
|
41 |
/**
|
42 |
* @defgroup analog Analog
|
43 |
* @brief Functions for reading analog input
|
44 |
*
|
45 |
* @{
|
46 |
**/
|
47 |
|
48 |
/* Analog state variables */
|
49 |
/** @todo Fix types: static */
|
50 |
unsigned int port; /**< The current port from which we are reading from. */ |
51 |
|
52 |
|
53 |
/**
|
54 |
* @brief Outputs current analog data at a given port
|
55 |
*
|
56 |
* Serves the service query_analog by responding to service requests with the
|
57 |
* speeds of the motors.
|
58 |
* @param req The request. The only field is the units requested.
|
59 |
* @param res The response. The fields will be filled with values.
|
60 |
*/
|
61 |
bool analog_query(motors::query_analog::Request &req,
|
62 |
motors::query_analog::Response &res) |
63 |
{ |
64 |
int port = port;
|
65 |
res.sensor_data = get_sensor_data(port); |
66 |
|
67 |
ROS_DEBUG("Analog data queried");
|
68 |
return true; |
69 |
} |
70 |
|
71 |
/*
|
72 |
* @brief
|
73 |
*
|
74 |
* Given a port number, returns the analog data present at the port
|
75 |
*
|
76 |
* @param port The port we want to read from
|
77 |
*/
|
78 |
unsigned int get_sensor_data(int port){ |
79 |
|
80 |
ROS_DEBUG("Got Analog data from the sensor");
|
81 |
return 0; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* @brief Motors driver. This is a ROS node that controls motor speeds.
|
86 |
*
|
87 |
* This is the main function for the motors node. It is run when the node
|
88 |
* starts and initializes the motors. It then subscribes to the
|
89 |
* set_motors, and set_motor_speeds topics, and advertises the
|
90 |
* query_motors service.
|
91 |
*
|
92 |
* @param argc The number of command line arguments (should be 1)
|
93 |
* @param argv The array of command line arguments
|
94 |
**/
|
95 |
int main(int argc, char **argv) |
96 |
{ |
97 |
/* Initialize in ROS the motors driver node */
|
98 |
ros::init(argc, argv, "analog_driver");
|
99 |
|
100 |
/* Advertise that this serves the query_analog service */
|
101 |
ros::NodeHandle n; |
102 |
ros::ServiceServer service = n.advertiseService("query_analog",
|
103 |
analog_query); |
104 |
|
105 |
/* Initialize hardware for motors */
|
106 |
// Hardware init functions here
|
107 |
ros::spin(); |
108 |
|
109 |
return 0; |
110 |
} |
111 |
|
112 |
/** @} **/
|