00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <ros/ros.h>
00039 #include <tf/transform_broadcaster.h>
00040 #include <nav_msgs/Odometry.h>
00041 #include <geometry_msgs/Twist.h>
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
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