setup_miniq.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2012, ISR University of Coimbra.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the ISR University of Coimbra nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Gonçalo Cabrita on 11/09/2012
00036 *********************************************************************/
00037 
00038 #include <ros/ros.h>
00039 #include <tf/transform_broadcaster.h>
00040 #include <nav_msgs/Odometry.h>                  // odom
00041 #include <geometry_msgs/Twist.h>                // cmd_vel
00042 
00043 #include "miniQ.h"
00044 
00045 miniQ robot = miniQ();
00046 
00047 int main(int argc, char** argv)
00048 {
00049         ros::init(argc, argv, "miniq_node");
00050 
00051         ROS_INFO("miniQ setup for ROS");
00052 
00053         ros::NodeHandle n;
00054         ros::NodeHandle pn("~");
00055     
00056         std::string port;
00057         pn.param<std::string>("port", port, "/dev/ttyUSB0");
00058         int baudrate;
00059         pn.param("baudrate", baudrate, 57600);
00060 
00061         // Setup parameters
00062         int starting_l_kp;
00063         pn.param("starting_l_kp", starting_l_kp, 350);
00064         int starting_l_ki;
00065         pn.param("starting_l_ki", starting_l_ki, 80);
00066         int starting_l_kd;
00067         pn.param("starting_l_kd", starting_l_kd, 0);
00068 
00069         int running_l_kp;
00070         pn.param("running_l_kp", running_l_kp, 150);
00071         int running_l_ki;
00072         pn.param("running_l_ki", running_l_ki, 20);
00073         int running_l_kd;
00074         pn.param("running_l_kd", running_l_kd, 2);
00075 
00076         int starting_r_kp;
00077         pn.param("starting_r_kp", starting_r_kp, 350);
00078         int starting_r_ki;
00079         pn.param("starting_r_ki", starting_r_ki, 80);
00080         int starting_r_kd;
00081         pn.param("starting_r_kd", starting_r_kd, 0);
00082 
00083         int running_r_kp;
00084         pn.param("running_r_kp", running_r_kp, 150);
00085         int running_r_ki;
00086         pn.param("running_r_ki", running_r_ki, 20);
00087         int running_r_kd;
00088         pn.param("running_r_kd", running_r_kd, 2);
00089 
00090         int battery_type;
00091         pn.param("battery_type", battery_type, 0);
00092 
00093         int mode;
00094         pn.param("mode", mode, 0);
00095 
00096         double odometry_d;
00097         pn.param("odometry_d", odometry_d, 0.0);
00098         double odometry_yaw;
00099         pn.param("odometry_yaw", odometry_yaw, 0.0);
00100 
00101         double gas_a;
00102         pn.param("gas_a", gas_a, 0.0);
00103         double gas_b;
00104         pn.param("gas_b", gas_b, 0.0);
00105     
00106     double timeout;
00107         pn.param("timeout", timeout, 0.0);
00108     
00109         if(!miniQ::openPort((char*)port.c_str(), baudrate))
00110         {
00111                 ROS_FATAL("miniQ -- Failed to open serial port %s at %d baud!", port.c_str(), baudrate);
00112                 ROS_BREAK();
00113         }
00114         ROS_INFO("miniQ -- Successfully connected to the miniQ!");
00115     
00116         ros::Duration(2.5).sleep();
00117     
00118         if(!robot.checkVersion())
00119         {
00120                 ROS_FATAL("miniQ -- The firmware version of the miniQ robot is not compatible with this ROS node!");
00121                 ROS_BREAK();
00122         }
00123     
00124         ROS_INFO("miniQ -- Setting communication mode to %s...", mode==0 ? "Serial" : "XBee API");
00125         if(!robot.setMode(mode)) ROS_ERROR("miniQ -- ERROR!");
00126         else ROS_INFO("miniQ -- DONE.");
00127 
00128         ros::Duration(1.0).sleep();
00129 
00130         ROS_INFO("miniQ -- Setting battery type to %s...", battery_type==0 ? "Li-Ion" : "4 AA");
00131         if(!robot.setBatteryType(battery_type)) ROS_ERROR("miniQ -- ERROR!");
00132         else ROS_INFO("miniQ -- DONE.");
00133 
00134         ros::Duration(1.0).sleep();
00135         
00136         ROS_INFO("miniQ -- Setting starting PID gains for left motor kp:%d ki:%d kd:%d", starting_l_kp, starting_l_ki, starting_l_kd);
00137         if(!robot.setPIDGains(starting_l_kp, starting_l_ki, starting_l_kd, miniQ::LeftStartingPID)) ROS_ERROR("miniQ -- ERROR!");
00138         else ROS_INFO("miniQ -- DONE.");
00139 
00140         ros::Duration(1.0).sleep();
00141 
00142         ROS_INFO("miniQ -- Setting running PID gains for left motor kp:%d ki:%d kd:%d", running_l_kp, running_l_ki, running_l_kd);
00143         if(!robot.setPIDGains(running_l_kp, running_l_ki, running_l_kd, miniQ::LeftRunningPID)) ROS_ERROR("miniQ -- ERROR!");
00144         else ROS_INFO("miniQ -- DONE.");
00145 
00146         ros::Duration(1.0).sleep();
00147         
00148         ROS_INFO("miniQ -- Setting starting PID gains for right motor kp:%d ki:%d kd:%d", starting_r_kp, starting_r_ki, starting_r_kd);
00149         if(!robot.setPIDGains(starting_r_kp, starting_r_ki, starting_r_kd, miniQ::RightStartingPID)) ROS_ERROR("miniQ -- ERROR!");
00150         else ROS_INFO("miniQ -- DONE.");
00151 
00152         ros::Duration(1.0).sleep();
00153 
00154         ROS_INFO("miniQ -- Setting running PID gains for right motor kp:%d ki:%d kd:%d", running_r_kp, running_r_ki, running_r_kd);
00155         if(!robot.setPIDGains(running_r_kp, running_r_ki, running_r_kd, miniQ::RightRunningPID)) ROS_ERROR("miniQ -- ERROR!");
00156         else ROS_INFO("miniQ -- DONE.");
00157 
00158         ros::Duration(1.0).sleep();
00159 
00160         ROS_INFO("miniQ -- Setting odometry callibration coefficients d:%lf yaw:%lf", odometry_d, odometry_yaw);
00161         if(!robot.setOdometryCallibration(odometry_d, odometry_yaw)) ROS_ERROR("miniQ -- ERROR!");
00162         else ROS_INFO("miniQ -- DONE.");
00163 
00164         ros::Duration(1.0).sleep();
00165 
00166         ROS_INFO("miniQ -- Setting gas sensor callibration coefficients a:%lf b:%lf", gas_a, gas_b);
00167         if(!robot.setGasSensorCallibration(gas_a, gas_b)) ROS_ERROR("miniQ -- ERROR!");
00168         else ROS_INFO("miniQ -- DONE.");                
00169 
00170         ros::Duration(1.0).sleep();
00171     
00172     ROS_INFO("miniQ -- Setting the timeout to %lf", timeout);
00173         if(!robot.setTimeout(timeout)) ROS_ERROR("miniQ -- ERROR!");
00174         else ROS_INFO("miniQ -- DONE.");        
00175 
00176         ROS_INFO("miniQ -- Setup was successfully! Goodbye!");
00177 
00178         return 0;
00179 }
00180 
00181 // EOF


lse_miniq_driver
Author(s): Gonçalo Cabrita
autogenerated on Mon Jan 6 2014 11:25:52