Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / sonar / src / sonar.cpp @ 85538662

History | View | Annotate | Download (3.64 KB)

1
/**
2
 * Copyright (c) 2007 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
/**
28
 * @file sonar.cpp
29
 * @brief Sonar
30
 *
31
 * Implementation of functions for sonar use.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Alex Zirbel
35
 **/
36

    
37
#include "scout/sonar.h"
38
#include "ros/ros.h"
39
#include <cstdlib>
40

    
41
/**
42
 * @defgroup sonar Sonar
43
 * @brief Functions for using the sonar
44
 *
45
 * @{
46
 **/
47

    
48
/** Current position of the sonar. Should only contain values in [0,23]. */
49
int8_t sonar_stepper_pos;
50
bool is_on;
51

    
52
/**
53
 * Initialize the sonar system. This must be called before sonar_read.
54
 * 
55
 * @see sonar_read
56
 * @see sonar_read_raw
57
 **/
58
void sonar_init(void)
59
{
60
    sonar_stepper_pos = 0;
61
}
62

    
63
/**
64
 * Turns the sonar on and off.
65
 */
66
bool handle_sonar_toggle(sonar::sonar_toggle::Request  &req,
67
                         sonar::sonar_toggle::Response &res)
68
{
69
    if (req.set_on)
70
        ROS_INFO("Turning on the sonar [unimplemented]");
71
    else
72
        ROS_INFO("Turning off the sonar [unimplemented]");
73

    
74
    res.ack = true;
75

    
76
    return true;
77
}
78

    
79
/**
80
 * @brief Sets the sonar scan range. Values from 0 to 23 are valid.
81
 * 
82
 * Handles setting the sonar scan range. The scan range is specified by
83
 * the front sonar, so a scan range of 0 to 23 is a full scan.
84
 * After the scan range is set, the robot will continue reading values
85
 * only from that range until the range is reset. Old values can be identified
86
 * by the header on the distance reading message.
87
 */
88
bool handle_sonar_set_scan(sonar::sonar_set_scan::Request  &req,
89
                           sonar::sonar_set_scan::Response &res)
90
{
91
    // Code to set the sonar to scan from
92
    // req.stop_l to req.stop_r
93

    
94
    ROS_INFO("Setting sonar scan range to [%s, %s] [unimplemented]",
95
             req.stop_l,
96
             req.stop_r);
97
    
98
    res.ack = true;
99

    
100
    return true;
101
}
102

    
103
/**
104
 * Initialize the sonar driver. This must be called before any sonar
105
 * requests are made. It will then run in the background until the sonar node is
106
 * shut down.
107
 **/
108
void main(int argc, char **argv)
109
{
110
    is_on = true;
111

    
112
    /* Initialize hardware for sonar */
113
    //Hardware init functions here
114
    sonar_init();
115

    
116
    /* Initialize the sonar driver node in ROS */
117
    ros::init(argc, argv, "sonar_driver");
118

    
119
    /* Advertise messages and services */
120
    ros::NodeHandle n;
121
    ros:ServiceServer service0 = n.advertiseService("sonar_toggle",
122
                                                    handle_sonar_toggle);
123
    ros:ServiceServer service1 = n.advertiseService("sonar_set_scan",
124
                                                    handle_sonar_set_scan);
125

    
126
    ROS_INFO("Sonar: Ready");
127
    ros::spin();
128

    
129
    return 0;
130
}
131

    
132
/** @} **/