commit 34a60a3b2ffaef82b1e09ae7402d4c1283165361
Author: Priya <pdeo@Phlegethon.(none)>
Date:   Sun Apr 14 14:34:42 2013 -0400

    Added RungeKutta to the helper classes and changed the odometry to use that instead. Also created PaintboardControl files, changed the Makefile to compile all control classes and deleted Cliffsensor control becase it did not work.

diff --git a/scout/libscout/CMakeLists.txt b/scout/libscout/CMakeLists.txt
index 50cd3cf..2567092 100644
--- a/scout/libscout/CMakeLists.txt
+++ b/scout/libscout/CMakeLists.txt
@@ -36,8 +36,8 @@ set(MAIN_FILES src/Sensors.cpp src/Behavior.cpp src/BehaviorList.cpp src/Behavio
 FILE(GLOB BEHAVIOR_FILES "${PROJECT_SOURCE_DIR}/src/behaviors/*.cpp")
 FILE(GLOB TEST_BEHAVIOR_FILES "${PROJECT_SOURCE_DIR}/src/test_behaviors/*.cpp")
 FILE(GLOB HELPER_FILES "${PROJECT_SOURCE_DIR}/src/helper_classes/*.cpp")
+FILE(GLOB CONTROL_CLASSES "${PROJECT_SOURCE_DIR}/src/*Control.cpp")
+set(WIRELESS_CONTROL_CLASSES src/WirelessSender.cpp src/WirelessReceiver.cpp)
 
-set(CONTROL_CLASSES src/MotorControl.cpp src/SonarControl.cpp src/HeadlightControl.cpp src/ButtonControl.cpp src/WirelessSender.cpp src/WirelessReceiver.cpp src/EncodersControl.cpp src/LinesensorControl.cpp src/MetalDetectorControl.cpp)
-
-rosbuild_add_executable(libscout ${MAIN_FILES} ${BEHAVIOR_FILES} ${TEST_BEHAVIOR_FILES} ${CONTROL_CLASSES} ${HELPER_FILES})
+rosbuild_add_executable(libscout ${MAIN_FILES} ${CONTROL_CLASSES} ${WIRELESS_CONTROL_CLASSES} ${HELPER_FILES} ${BEHAVIOR_FILES} ${TEST_BEHAVIOR_FILES})
 rosbuild_add_compile_flags(libscout -std=c++0x)
diff --git a/scout/libscout/src/CliffsensorControl.cpp b/scout/libscout/src/CliffsensorControl.cpp
deleted file mode 100644
index 0aed628..0000000
--- a/scout/libscout/src/CliffsensorControl.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * 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 CliffsensorControl.cpp
- * @brief Contains code to control the cliffsensor.
- *
- * Implementation of functions for cliffsensor use.
- *
- * @author Colony Project, CMU Robotics Club
- * @author Priyanka Deo
- * @author Leon Zhang
- **/
-
-#include "ros/ros.h"
-#include "CliffsensorControl.h"
-#include <cstdlib>
-
-/**
- * @brief Initializes the Cliffsensor module in libscout.
- *
- * This is the main function for the cliffsensors node. It is run when the node
- * starts and initializes the cliffsensors. It then subscribes to the
- * cliff_status_changed topics
- **/
-CliffsensorControl::CliffsensorControl(const ros::NodeHandle& libscout_node,
-                                  std::string scoutname) : node(libscout_node)
-{
-    /* Subscribe to the cliff_status_changed topic */
-    cliff_status_changed_sub = node.subscribe("cliff_status_changed", 
-                             QUEUE_SIZE, &CliffsensorControl::changed_cliff_status, this);
-
-    ros::spin();
-}
-
-/**
- * @brief Changes cliff sensor status
- *
- * Changes cliff sensor status based on subscription to topic cliff_status_changed
- *
- * @param msg The message from the cliff_status_changed topic, containing 
- * status of all cliff sensors.
- *
- */
-void CliffsensorControl::changed_cliff_status(const ::messages::cliff_status_changed::ConstPtr& msg)
-{
-    front_raw = msg->front_raw;
-    left_raw = msg->left_raw;
-    right_raw = msg->right_raw;
-    return;
-}
-
-/**
- * @brief get the current raw value of the front cliffsensor
- * @return the current raw value of the front cliffsensor
- */
-int CliffsensorControl::get_front_raw()
-{
-    return front_raw;
-}
-
-/**
- * @brief get the current raw value of the left cliffsensor
- * @return the current raw value of the left cliffsensor
- */
-int CliffsensorControl::get_left_raw()
-{
-    return left_raw;
-}
-
-/**
- * @brief get the current raw value of the right cliffsensor
- * @return the current raw value of the right cliffsensor
- */
-int CliffsensorControl::get_right_raw()
-{
-    return right_raw;
-}
-
-/**
- * @brief check if a cliff is being detected
- * @return true if there is a cliff, otherwise
- */
-bool CliffsensorControl::check_is_cliff()
-{
-    return (front_raw || left_raw || right_raw);
-}
diff --git a/scout/libscout/src/CliffsensorControl.h b/scout/libscout/src/CliffsensorControl.h
deleted file mode 100644
index 9c9b044..0000000
--- a/scout/libscout/src/CliffsensorControl.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * 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 CliffsensorControl.h
- * @brief Contains cliffsensor declarations and functions.
- * 
- * Contains functions and definitions for the use of
- * cliffsensors.
- *
- * @author Colony Project, CMU Robotics Club
- * @author Priyanka Deo
- * @author Leon Zhang
- **/
-
-#ifndef _CLIFFSENSOR_H_
-#define _CLIFFSENSOR_H_
-
-#include <messages/query_cliff.h>
-#include <messages/cliff_status_changed.h>
-#include "constants.h"
-
-#define CLIFF_DETECTED 0x0
-#define NO_CLIFF 0x1
-
-class CliffsensorControl
-{
-    public:
-        CliffsensorControl(const ros::NodeHandle& libscout_node, std::string scoutname);
-
-        /** @brief Responds to topic to change cliff sensor status. **/
-        void changed_cliff_status(
-                        const messages::cliff_status_changed::ConstPtr& msg);
-
-        int get_front_raw();
-        int get_left_raw();
-        int get_right_raw();
-        bool check_is_cliff();
-
-    private:
-        /* Cliffsensor state variables
-         */
-        int front_raw; /**< The current raw value 
-                        data of the front cliffsensor. */
-        int left_raw; /**< The current raw value data of 
-                        the left cliffsensor. */
-        int right_raw; /**< The current raw value data of 
-                        the right cliffsensor. */
-
-        ros::Subscriber cliff_status_changed_sub;
-        ros::NodeHandle node; 
-};
-
-#endif
diff --git a/scout/libscout/src/PaintBoardControl.cpp b/scout/libscout/src/PaintBoardControl.cpp
new file mode 100644
index 0000000..b0e9f09
--- /dev/null
+++ b/scout/libscout/src/PaintBoardControl.cpp
@@ -0,0 +1,105 @@
+/**
+ * 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 PaintBoardControl.cpp
+ * @brief Contains paintboard declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * paintboards
+ *
+ * @author Colony Project, CMU Robotics Club
+ * @author Priyanka Deo
+ **/
+
+#include "PaintBoardControl.h"
+
+using namespace std;
+
+/**
+ * @brief Initialize the paintboards module of libscout.
+ *
+ * Initialize the libscout node as a publisher of set_paintboards and a client of
+ * query_paintboards.
+ */
+PaintBoardControl::PaintBoardControl(const ros::NodeHandle& libscout_node,
+                           string scoutname)
+    : node(libscout_node)
+{
+    set_paintboard_pub =
+        node.advertise< ::messages::set_paintboard>(scoutname + "/set_paintboard",
+                                           QUEUE_SIZE, true);
+    query_paintboard_client =
+        node.serviceClient< ::messages::query_paintboard>(scoutname + "/query_paintboard");
+}
+
+PaintBoardControl::~PaintBoardControl()
+{
+  set(STOP_PAINT);
+}
+
+/**
+ * @brief Sets all the speeds according to the specificiation of which paintboard
+ *        to set.
+ *
+ * @param which A bitmask of which paintboard need to be set.
+ * @param speed The value to set the paintboard to.
+ * @param units The units the speed is expressed in.
+ * @return Function status
+ */
+void PaintBoardControl::set(int paintboard_setting)
+{
+    ::messages::set_paintboard msg;
+    
+    msg.setting = paintboard_setting;
+
+    set_paintboard_pub.publish(msg);
+    ros::spinOnce();
+}
+
+/**
+ * @brief Query the current speeds of the paintboard
+ *
+ * Sends a request to the query_paintboard service which will reply with the
+ *  current setting of the paintboard.
+ *
+ * @param which A bitmask that will specify which motor speed should be
+ *  returned
+ * @return The speed of the selected motor
+ */
+int PaintBoardControl::query()
+{
+    ::messages::query_paintboard srv;
+    if(query_paintboard_client.call(srv))
+    {
+      return srv.response.setting;
+    }
+    else
+    {
+        ROS_FATAL("Failed to call service query_paintboard");
+    }
+
+    return -1;
+}
diff --git a/scout/libscout/src/PaintBoardControl.h b/scout/libscout/src/PaintBoardControl.h
new file mode 100644
index 0000000..3c9a9fd
--- /dev/null
+++ b/scout/libscout/src/PaintBoardControl.h
@@ -0,0 +1,72 @@
+/**
+ * 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 PaintBoardControl.h
+ * @brief Contains motor declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * motors
+ *
+ * @author Colony Project, CMU Robotics Club
+ * @author Priyanka Deo
+ **/
+
+#ifndef _PAINT_BOARD_CONTROL_H_
+#define _PAINT_BOARD_CONTROL_H_
+
+#include <ros/ros.h>
+#include "constants.h"
+#include <messages/set_paintboard.h>
+#include <messages/query_paintboard.h>
+
+#define STOP_PAINT 0
+#define DISPENSE_PAINT 1
+
+class PaintBoardControl
+{
+    public:
+        /** Set up the paintboard node and prepare to communicate over ROS */
+        PaintBoardControl(const ros::NodeHandle& libscout_node,
+                     std::string scoutname);
+
+        ~PaintBoardControl();
+
+        /** Turns the paintboard on or off. */
+        void set(int paintboard_setting);
+
+        /** Checks whether the paintboard is currently dispensing paint */
+        int query();
+    
+    private:
+        /** ROS publisher and client declaration */
+        ros::Publisher set_paintboard_pub;
+        ros::ServiceClient query_paintboard_client;
+
+        ros::NodeHandle node;
+};
+
+#endif
+
diff --git a/scout/libscout/src/Sensors.h b/scout/libscout/src/Sensors.h
index f66f278..5de4615 100644
--- a/scout/libscout/src/Sensors.h
+++ b/scout/libscout/src/Sensors.h
@@ -49,6 +49,7 @@
 #include "LinesensorControl.h"
 #include "WirelessSender.h"
 #include "WirelessReceiver.h"
+#include "PaintBoardControl.h"
 
 class Sensors
 {
@@ -71,7 +72,7 @@ class Sensors
         LinesensorControl * linesensor;
         WirelessSender * wl_sender;
         WirelessReceiver * wl_receiver;
-        
+        PaintBoardControl * paintboard;        
 };
 
 
diff --git a/scout/libscout/src/helper_classes/RungaKutta.cpp b/scout/libscout/src/helper_classes/RungaKutta.cpp
new file mode 100644
index 0000000..58ce275
--- /dev/null
+++ b/scout/libscout/src/helper_classes/RungaKutta.cpp
@@ -0,0 +1,49 @@
+#include "RungaKutta.h"
+#include <math.h>
+
+using namespace std;
+
+vector<double> RungaKutta::integrate(vector<double> a, vector<double> b, double t)
+{
+  //Copy over the a vector.
+  vector<double> result(a);
+  //Add half a timestep to the starting conditions.
+  for(unsigned int i=0; i<a.size(); i++)
+  {
+    result[i] += t*b[i];
+  }
+  //Return the integrated result.
+  return result;
+}
+
+vector<double> RungaKutta::diff_drive_robot(vector<double> x)
+{
+  vector<double> dx(5,0);
+  dx[0] = x[3] * cos(x[2]);
+  dx[1] = x[3] * sin(x[2]);
+  dx[2] = x[4];
+  dx[3] = x[3];
+  dx[4] = x[4];
+  return dx;
+}
+
+vector<double> RungaKutta::rk4(vector<double> start,
+    vector<double> (*func)(vector<double>),
+    double loop_time)
+{
+  vector<double> k0 = func(start);
+  vector<double> temp_k0 = integrate(start, k0, loop_time/2);
+  vector<double> k1 = func(temp_k0);
+  vector<double> temp_k1 = integrate(start, k1, loop_time/2);
+  vector<double> k2 = func(temp_k1);
+  vector<double> temp_k2 = integrate(start, k2, loop_time);
+  vector<double> k3 = func(temp_k2);
+  
+  // Average out each loop's result.
+  vector<double> result(start);
+  for(unsigned int i=0; i<result.size(); i++)
+  {
+    result[i] = loop_time/6*(k0[i]+2*k1[i]+2*k2[i]+k3[i]);
+  }
+  return result;
+}
diff --git a/scout/libscout/src/helper_classes/RungaKutta.h b/scout/libscout/src/helper_classes/RungaKutta.h
new file mode 100644
index 0000000..03d8406
--- /dev/null
+++ b/scout/libscout/src/helper_classes/RungaKutta.h
@@ -0,0 +1,21 @@
+#ifndef _RUNGA_KUTTA_H_
+#define _RUNGA_KUTTA_H_
+
+#include <vector>
+
+class RungaKutta
+{
+  public:
+    static std::vector<double> rk4(
+        std::vector<double> start,
+        std::vector<double> (*func)(std::vector<double>),
+        double loop_time);
+    static std::vector<double> diff_drive_robot(std::vector<double> x);
+  private:
+    static std::vector<double> integrate(
+        std::vector<double> a,
+        std::vector<double> b,
+        double t);
+};
+
+#endif
diff --git a/scout/libscout/src/test_behaviors/Odometry_new.cpp b/scout/libscout/src/test_behaviors/Odometry_new.cpp
index 35f5932..23652a7 100644
--- a/scout/libscout/src/test_behaviors/Odometry_new.cpp
+++ b/scout/libscout/src/test_behaviors/Odometry_new.cpp
@@ -1,5 +1,5 @@
-
 #include "Odometry_new.h"
+#include "../helper_classes/RungaKutta.h"
 
 using namespace std;
 
@@ -22,7 +22,7 @@ void Odometry_new::get_position(double loop_time)
   float avg_left_ticks, avg_right_ticks;
   float ang_vl, ang_vr, lin_vl, lin_vr;
   float robot_v, robot_w;
-  float k00, k01, k02, k10, k11, k12, k20, k21, k22, k30, k31, k32;
+
   // figure out the encoder ticks during the time
   encoder_readings scout_enc = encoders->query();
   motor_fl_ticks_iter = scout_enc.fl_ticks - motor_fl_ticks_last;
@@ -30,7 +30,9 @@ void Odometry_new::get_position(double loop_time)
   motor_bl_ticks_iter = scout_enc.bl_ticks - motor_bl_ticks_last;
   motor_br_ticks_iter = scout_enc.br_ticks - motor_br_ticks_last;
   
-  // update the 
+  ROS_INFO("%d  %d", motor_fl_ticks_iter, motor_fr_ticks_iter);
+
+  // update the tick values
   motor_fl_ticks_last = scout_enc.fl_ticks;
   motor_fr_ticks_last = scout_enc.fr_ticks;
   motor_bl_ticks_last = scout_enc.bl_ticks;
@@ -58,27 +60,15 @@ void Odometry_new::get_position(double loop_time)
   robot_w = (lin_vr - lin_vl)/WHEEL_B;
 
   // now use RK4 to integrade the velocities to get the the move in pos
-  k00 = robot_v * cos(scout_pos->theta);
-  k01 = robot_v * sin(scout_pos->theta);
-  k02 = robot_w;
-  
-  k10 = robot_v * cos(scout_pos->theta + loop_time/2*k02);
-  k11 = robot_v * sin(scout_pos->theta + loop_time/2*k02);
-  k12 = robot_w;
-
-  k20 = robot_v * cos(scout_pos->theta + loop_time/2*k12);
-  k21 = robot_v * sin(scout_pos->theta + loop_time/2*k12);
-  k22 = robot_w;
-
-  k30 = robot_v * cos(scout_pos->theta + loop_time * k22);
-  k31 = robot_v * sin(scout_pos->theta + loop_time * k22);
-  k32 = robot_w;
-
-  scout_pos->x += loop_time/6 * (k00+2*(k10+k20)+k30);
-  scout_pos->y += loop_time/6 * (k01+2*(k11+k21)+k31);
-  scout_pos->theta += loop_time/6 * (k02+2*(k12+k22)+k32);
+  double state_temp[] = {scout_pos->x, scout_pos->y, scout_pos->theta,
+      robot_v, robot_w};
+  vector<double> state (state_temp, state_temp+5);
 
+  vector<double> new_state = RungaKutta::rk4(state, RungaKutta::diff_drive_robot, loop_time);
 
+  scout_pos->x = new_state[0];
+  scout_pos->y = new_state[1];
+  scout_pos->theta = new_state[2];
 }
 
 void Odometry_new::run()
@@ -87,6 +77,9 @@ void Odometry_new::run()
   double last_time = Time::now().toSec();
   double loop_time, current_time;
 
+  // Reset encoders.
+  encoders->reset();
+
   //Rate r(LOOP_RATE); 
   Duration r = Duration(LOOP_TIME);
 
diff --git a/scout/messages/msg/set_paintboard.msg b/scout/messages/msg/set_paintboard.msg
new file mode 100644
index 0000000..36eb98b
--- /dev/null
+++ b/scout/messages/msg/set_paintboard.msg
@@ -0,0 +1,3 @@
+# The absolute motor speeds to set
+int8 setting
+
diff --git a/scout/messages/srv/query_paintboard.srv b/scout/messages/srv/query_paintboard.srv
new file mode 100644
index 0000000..4da34c6
--- /dev/null
+++ b/scout/messages/srv/query_paintboard.srv
@@ -0,0 +1,2 @@
+---
+int8 setting
