commit 65c7f52bb1c6183c6ab2a09be2a1c83c3a925eed
Author: pdeo <pdeo@roboclub8.frc.ri.cmu.edu>
Date:   Mon Dec 26 16:49:17 2011 -0500

    Created SonarControl files. Not tested and therefore not included in libscout interface yet.

diff --git a/scout/libscout/src/SonarControl.cpp b/scout/libscout/src/SonarControl.cpp
new file mode 100644
index 0000000..aa08abe
--- /dev/null
+++ b/scout/libscout/src/SonarControl.cpp
@@ -0,0 +1,159 @@
+/**
+ * Copyright (c) 2011 Colony Project
+ * 
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+/**
+ * @file SonarControl.cpp
+ * @brief Contains sonar function imeplementations
+ * 
+ * Contains functions for the use of sonar control.
+ *
+ * @author Colony Project, CMU Robotics Club
+ * @author Priyanka Deo
+ **/
+
+#include "SonarControl.h"
+
+/**
+ * @brief Initialize the sonar module of libscout.
+ *
+ * Initialize the libscout node as a publisher of sonar_set_scan and 
+ * sonar_toggle and a client of query_sonar.
+ */
+SonarControl::SonarControl(const ros::NodeHandle& libscout_node)
+    : node(libscout_node)
+{
+    sonar_set_scan_pub =
+        node.advertise<sonar::sonar_set_scan>("set_sonar_scan", QUEUE_SIZE);
+    sonar_toggle_pub = 
+	node.advertise<sonar::sonar_toggle>("toggle_sonar", QUEUE_SIZE);
+    query_sonar =
+        node.serviceClient<sonar::sonar_direction>("query_sonar");
+}
+
+/**
+ * @brief Sets the sonar to a position.
+ *
+ * @param position Value between 0-180 of degree position to set sonar
+ * @return NONE
+ */
+void SonarControl::set(int position)
+{
+    set_range(position, position);
+}
+
+/**
+ * @brief Sets the sonar to scan between two positions
+ *
+ * @param start_pos The leftmost (smallest) value that the sonar can take
+ * @param end_pos The rightmost (largest) value that the sonar can take
+ * @return NONE
+ */
+void SonarControl::set_range(int start_pos, int end_pos)
+{
+    //TODO Enable some checks of start and end position
+    sonar::sonar_set_scan msg;
+
+    msg.stop_l = start_pos;
+    msg.stop_r = end_pos;
+
+    sonar_set_scan_pub.publish(msg);
+    ros::spinOnce();
+}
+
+/**
+ * @brief Query the current front sonar readings
+ *
+ * Sends a request to the query_sonar service which will reply with the
+ *  current readings of the sonar.
+ *
+ * @TODO Change so we can get multiple sonar readings with one call
+ *
+ * @return The reading of the front sonar or LIB_ERR.
+ */
+float SonarControl::query_front()
+{
+    sonar::sonar_direction srv;
+    if(query_sonar.call(srv))
+    {
+        srv.response.distance0;
+    }
+    else
+    {
+        ROS_ERROR("Failed to call service query_motors");
+        return LIB_ERROR;
+    }
+
+    return 0;
+}
+
+/**
+ * @brief Query the current back sonar readings
+ *
+ * Sends a request to the query_sonar service which will reply with the
+ *  current readings of the sonar.
+ *
+ * @TODO Change so we can get multiple sonar readings with one call
+ *
+ * @return The reading of the back sonar or LIB_ERR.
+ */
+float SonarControl::query_back()
+{
+    sonar::sonar_direction srv;
+    if(query_sonar.call(srv))
+    {
+        srv.response.distance1;
+    }
+    else
+    {
+        ROS_ERROR("Failed to call service query_motors");
+        return LIB_ERROR;
+    }
+
+    return 0;
+}
+
+/**
+ * @brief Converts value returne by sonar to physical distances.
+ *
+ * @param sonar_value The returned value of the sonar
+ * @return The physical distance measured by the sonar.
+ **/
+float sonar_to_dist(float sonar_value)
+{
+    //TODO impelement later based on sonar readings
+    return sonar_value;
+}
+
+/**
+ * @brief Converts values from physical distances to values read by sonar
+ *
+ * @param distance The physical distance as measured.
+ * @return The value read by the sonar that corresponds to the given distance
+ **/
+float dist_to_sonar(float distance)
+{
+    //TODO implement later based on sonar readings
+    return distance;
+}
diff --git a/scout/libscout/src/SonarControl.h b/scout/libscout/src/SonarControl.h
new file mode 100644
index 0000000..b2a570f
--- /dev/null
+++ b/scout/libscout/src/SonarControl.h
@@ -0,0 +1,82 @@
+/**
+ * Copyright (c) 2011 Colony Project
+ * 
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+/**
+ * @file SonarControl.h
+ * @brief Contains sonar declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * sonar
+ *
+ * @author Colony Project, CMU Robotics Club
+ * @author Priyanka Deo
+ **/
+
+#ifndef _SONAR_CONTROL_H_
+#define _SONAR_CONTROL_H_
+
+#include <ros/ros.h>
+/// @TODO maybe not so good! Then packages have to depend on libscout.
+#include <libscout/constants.h>
+#include <sonar/sonar_set_scan.h>
+#include <sonar/sonar_toggle.h>
+#include <sonar/sonar_direction.h>
+
+class SonarControl
+{
+    public:
+        /** Set up the motor node and prepare to communicate over ROS */
+        SonarControl(const ros::NodeHandle& libscout_node);
+
+        /** Sets sonar to a position (0-180 deg) specified by input */
+        void set(int position);
+
+	/** Sets sonar to scan a range in 0-180 specified by input */
+	void set_range(int start_pos, int end_pos);	
+
+        /** Returns the distance readings of sonars */
+        float query_front(void);
+	float query_back(void);
+    
+    private:
+	/** Converts between values outputted by sensor and physical distances */
+        float sonar_to_dist(float sonar_value);
+        float dist_to_sonar(float distance);
+
+        /* Front and back distance values read by sonar. */
+        float front_dist;
+        float back_dist;
+
+        /** ROS publisher and client declaration */
+        ros::Publisher sonar_set_scan_pub;
+	ros::Publisher sonar_toggle_pub;
+        ros::ServiceClient query_sonar;
+
+        ros::NodeHandle node;
+
+};
+
+#endif
+
