root / scout / encoders / src / encoders.cpp @ b23c6bbb
History | View | Annotate | Download (3.4 KB)
1 | 14241f84 | Lalitha Ganesan | /**
|
---|---|---|---|
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 | 14241f84 | Lalitha Ganesan | |
26 | /**
|
||
27 | * @file encoders.cpp
|
||
28 | * @brief Encoders
|
||
29 | *
|
||
30 | * Implementation of functions for encoder use.
|
||
31 | *
|
||
32 | * @author Colony Project, CMU Robotics Club
|
||
33 | ce559b91 | Alex Zirbel | * @author Alex Zirbel
|
34 | 14241f84 | Lalitha Ganesan | **/
|
35 | |||
36 | ce559b91 | Alex Zirbel | #include <ros/ros.h> |
37 | |||
38 | 14241f84 | Lalitha Ganesan | #include "encoders.h" |
39 | |||
40 | /**
|
||
41 | * @defgroup encoders Encoders
|
||
42 | * @brief Functions for using the encoders
|
||
43 | *
|
||
44 | ce559b91 | Alex Zirbel | * @{
|
45 | */
|
||
46 | 14241f84 | Lalitha Ganesan | |
47 | /* Encoder state variables */
|
||
48 | ce559b91 | Alex Zirbel | /** @todo Fix types: static */
|
49 | /** @todo Fix integer overflow possibility */
|
||
50 | |||
51 | 7cb5de78 | Ben Wasserman | /* The current position of each encoder, measured in encoder ticks */
|
52 | ce559b91 | Alex Zirbel | int encoder_fl_index;
|
53 | int encoder_fr_index;
|
||
54 | int encoder_bl_index;
|
||
55 | int encoder_br_index;
|
||
56 | |||
57 | 7cb5de78 | Ben Wasserman | /* The current distance each encoder has traveled in ticks from last reset */
|
58 | int encoder_fl_distance;
|
||
59 | int encoder_fr_distance;
|
||
60 | int encoder_bl_distance;
|
||
61 | int encoder_br_distance;
|
||
62 | |||
63 | ce559b91 | Alex Zirbel | /**
|
64 | * @brief Outputs current encoder data
|
||
65 | *
|
||
66 | * Serves the service query_encoders by responding to service requests with the
|
||
67 | * encoder values.
|
||
68 | * @param req The request. The units that the response should be in.
|
||
69 | * @param res The response. The fields will be filled with values.
|
||
70 | */
|
||
71 | bool handle_encoders_query(encoders::query_encoders::Request &req,
|
||
72 | encoders::query_encoders::Response &res) |
||
73 | { |
||
74 | /* Put index, velocity, and distance data in message */
|
||
75 | res.fl_distance = encoder_fl_distance; |
||
76 | res.fr_distance = encoder_fr_distance; |
||
77 | res.bl_distance = encoder_bl_distance; |
||
78 | res.br_distance = encoder_br_distance; |
||
79 | |||
80 | ROS_DEBUG("Encoder values queried [Unimplemented]");
|
||
81 | return true; |
||
82 | } |
||
83 | 14241f84 | Lalitha Ganesan | |
84 | ce559b91 | Alex Zirbel | /**
|
85 | * @brief Encoders driver. This is a ROS node that controls encoders.
|
||
86 | 14241f84 | Lalitha Ganesan | *
|
87 | * This is the main function for the encoders node. It is run when the node
|
||
88 | * starts and initializes the encoders. It then publishes to the
|
||
89 | * encoder_state topic and advertises the query_encoders service.
|
||
90 | ce559b91 | Alex Zirbel | */
|
91 | int main(int argc, char **argv) |
||
92 | { |
||
93 | /* Initialize in ROS the encoders driver node */
|
||
94 | ros::init(argc, argv, "encoders_driver");
|
||
95 | 14241f84 | Lalitha Ganesan | |
96 | ce559b91 | Alex Zirbel | /* Advertise that this serves the query_encoders service */
|
97 | ros::NodeHandle n; |
||
98 | ros::ServiceServer service = |
||
99 | n.advertiseService("query_encoders",
|
||
100 | handle_encoders_query); |
||
101 | 14241f84 | Lalitha Ganesan | |
102 | ce559b91 | Alex Zirbel | /* Initialize hardware for motors */
|
103 | // Hardware init functions here
|
||
104 | 14241f84 | Lalitha Ganesan | |
105 | ce559b91 | Alex Zirbel | ROS_INFO("Ready to set encoders.");
|
106 | 14241f84 | Lalitha Ganesan | |
107 | ce559b91 | Alex Zirbel | // Acutally measure encoders and update values here
|
108 | 14241f84 | Lalitha Ganesan | |
109 | ce559b91 | Alex Zirbel | ros::spin(); |
110 | 14241f84 | Lalitha Ganesan | |
111 | ce559b91 | Alex Zirbel | return 0; |
112 | 14241f84 | Lalitha Ganesan | } |
113 | |||
114 | ce559b91 | Alex Zirbel | /** @} */ |