root / scout / libscout / src / CliffsensorControl.cpp @ fb61cb17
History | View | Annotate | Download (3.35 KB)
1 | d1ba04dc | Priya | /**
|
---|---|---|---|
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 CliffsensorControl.cpp
|
||
28 | * @brief Contains code to control the cliffsensor.
|
||
29 | *
|
||
30 | 3a73516c | Alex | * @defgroup motorcontrol MotorControl
|
31 | * @brief Functions which a behavior can use to control the motors.
|
||
32 | * @ingroup behavior
|
||
33 | d1ba04dc | Priya | *
|
34 | * @author Colony Project, CMU Robotics Club
|
||
35 | * @author Priyanka Deo
|
||
36 | * @author Leon Zhang
|
||
37 | 3a73516c | Alex | *
|
38 | * @{
|
||
39 | d1ba04dc | Priya | **/
|
40 | |||
41 | #include "ros/ros.h" |
||
42 | #include "CliffsensorControl.h" |
||
43 | #include <cstdlib> |
||
44 | |||
45 | /**
|
||
46 | * @brief Initializes the Cliffsensor module in libscout.
|
||
47 | *
|
||
48 | * This is the main function for the cliffsensors node. It is run when the node
|
||
49 | * starts and initializes the cliffsensors. It then subscribes to the
|
||
50 | * cliff_status_changed topics
|
||
51 | **/
|
||
52 | CliffsensorControl::CliffsensorControl(const ros::NodeHandle& libscout_node,
|
||
53 | std::string scoutname) : node(libscout_node)
|
||
54 | { |
||
55 | /* Subscribe to the cliff_status_changed topic */
|
||
56 | cliff_status_changed_sub = node.subscribe("cliff_status_changed",
|
||
57 | QUEUE_SIZE, &CliffsensorControl::changed_cliff_status, this);
|
||
58 | |||
59 | ros::spin(); |
||
60 | } |
||
61 | |||
62 | /**
|
||
63 | * @brief Changes cliff sensor status
|
||
64 | *
|
||
65 | * Changes cliff sensor status based on subscription to topic cliff_status_changed
|
||
66 | *
|
||
67 | * @param msg The message from the cliff_status_changed topic, containing
|
||
68 | * status of all cliff sensors.
|
||
69 | *
|
||
70 | */
|
||
71 | void CliffsensorControl::changed_cliff_status(const ::messages::cliff_status_changed::ConstPtr& msg) |
||
72 | { |
||
73 | front_raw = msg->cliff_status; |
||
74 | left_raw = msg->cliff_status; |
||
75 | right_raw = msg->cliff_status; |
||
76 | return;
|
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * @brief get the current raw value of the front cliffsensor
|
||
81 | * @return the current raw value of the front cliffsensor
|
||
82 | */
|
||
83 | int CliffsensorControl::get_front_raw()
|
||
84 | { |
||
85 | return front_raw;
|
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * @brief get the current raw value of the left cliffsensor
|
||
90 | * @return the current raw value of the left cliffsensor
|
||
91 | */
|
||
92 | int CliffsensorControl::get_left_raw()
|
||
93 | { |
||
94 | return left_raw;
|
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * @brief get the current raw value of the right cliffsensor
|
||
99 | * @return the current raw value of the right cliffsensor
|
||
100 | */
|
||
101 | int CliffsensorControl::get_right_raw()
|
||
102 | { |
||
103 | return right_raw;
|
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * @brief check if a cliff is being detected
|
||
108 | * @return true if there is a cliff, otherwise
|
||
109 | */
|
||
110 | bool CliffsensorControl::check_is_cliff()
|
||
111 | { |
||
112 | return (front_raw || left_raw || right_raw);
|
||
113 | } |
||
114 | 3a73516c | Alex | |
115 | /** @} */ |