Ros.cpp
Go to the documentation of this file.
00001 #include "Ros.h"
00002 #include "corobot.h"
00003 #include <QImage>
00004 #include <QGraphicsTextItem>
00005 #include <QPainter>
00006 #include <QGraphicsView>
00007 #include <math.h>
00008 #include <QImageReader>
00009 
00010 #include <vector>
00011 
00012 using namespace std;
00013 
00014 Ros::Ros(){
00015 
00016         speed_value = 100;
00017         speed_x = 0;
00018         speed_a = 0;
00019 
00020         arm_px = (double)UPPER_ARM_LENGTH_INCHES * (double)INCHES_TO_METERS;
00021         arm_py = (double)LOWER_ARM_LENGTH_INCHES * (double)INCHES_TO_METERS;
00022 
00023         scenes_rear_cam = NULL;
00024         scenes_ptz_cam = NULL;//front camera scene
00025         scenes = NULL;
00026         scenes_kinect_rgb = NULL;
00027         scenes_kinect_depth = NULL;
00028 
00029         pan = 0;
00030         tilt = 0;
00031         move_speed_level = 0;
00032         turning_speed_level = 0;
00033 
00034         turningRight = false;
00035         turningLeft = false;
00036 
00037 
00038         hokuyo_points_ = new Hokuyo_Points [683];
00039         speed_left = 0;
00040         speed_right = 0;
00041 
00042         initialized = false;
00043 }
00044 
00045 
00046 
00047 Ros::~Ros(){
00048     delete [] hokuyo_points_;
00049     hokuyo_points_ = NULL;
00050     if(driveControl_pub)
00051         this->motor_stop();
00052 }
00053 
00054 void Ros::subscribe()
00055 //function that initialize every ros variables declared
00056 
00057 {
00058     ros::NodeHandle n;
00059     ros::NodeHandle nh("~");
00060     nh.param("cameraRear_jpeg_compression", cameraRear_jpeg_compression, false);
00061     nh.param("cameraFront_jpeg_compression", cameraFront_jpeg_compression, false);
00062     nh.param("Lynxmotion_al5a", arm_al5a, false);
00063     nh.param("PhantomX_Pincher", arm_pincher, false);
00064     nh.param("PhantomX_Reactor", arm_reactor, false);
00065     nh.param("corobot_arm_ssc32", arm_old_ssc32, false);
00066     nh.param("corobot_arm_phidget", arm_old_phidget, false);
00067 
00068 
00069     emit arm_model(arm_al5a, arm_pincher, arm_reactor, arm_old_ssc32 || arm_old_phidget);
00070 
00071     setOdom_client = n.serviceClient<corobot_srvs::SetOdom>("set_odom");
00072     //driveControl_client = n.serviceClient<Coroware_teleop::SSC32NodeSetSpeed>("ssc32control/ssc32node_set_speed");
00073 
00074 
00075     //Advertise topics
00076     driveControl_pub = n.advertise<corobot_msgs::MotorCommand>("PhidgetMotor", 100);
00077     velocityValue_pub = n.advertise<corobot_msgs::velocityValue>("velocityValue", 100);
00078     moveArm_pub = n.advertise<corobot_msgs::MoveArm>("armPosition", 100);
00079     pan_tilt_control = n.advertise<corobot_msgs::PanTilt>("pantilt",5);
00080 
00081 
00082     //Subscribe to topics
00083     spatial=n.subscribe("spatial_data",1000, &Ros::spatialCallback,this);
00084     velocity= n.subscribe("odometry", 1000, &Ros::velocityCallback,this);
00085     ir= n.subscribe("infrared_data", 1000, &Ros::irCallback,this);
00086     power= n.subscribe<corobot_msgs::PowerMsg>("power_data", 1000, &Ros::powerCallback,this);
00087     bumper= n.subscribe("bumper_data", 1000, &Ros::bumperCallback,this);
00088     gripper= n.subscribe("gripper_data", 1000, &Ros::gripperCallback,this);
00089     cameraInfo= n.subscribe("camera_info", 1000, &Ros::cameraInfoCallback,this);
00090     cameraImage= n.subscribe("image_raw", 1000, &Ros::cameraImageCallback,this);
00091     gps= n.subscribe("fix", 1000, &Ros::gpsCallback,this);
00092     scan= n.subscribe("scan", 1000, &Ros::scanCallback,this);
00093     kinect_rgb = n.subscribe("/camera/rgb/image_color/compressed",100,&Ros::kinectrgbCallback,this);
00094     kinect_depth = n.subscribe("/camera/depth/image",100,&Ros::kinectdepthCallback,this);
00095   //  kinect_skel = n.subscribe("/skeletons",10,&Ros::kinectskelCallback,this);
00096     ssc32_info_sub = n.subscribe("ssc32_info", 10, &Ros::ssc32infoCallback, this);
00097     phidget_info_sub = n.subscribe("phidget_info", 10, &Ros::phidgetinfoCallback, this);
00098     takepic_sub = n.subscribe("takepicture", 10, &Ros::takepicCallback, this);
00099     map_image = n.subscribe("/map_image/full_with_position/compressed",10, &Ros::mapCallback,this);
00100 
00101     //Modified to compressed image
00102     if(cameraRear_jpeg_compression)
00103         rear_cam = n.subscribe("REAR/image_raw/compressed",10, &Ros::rear_camCallback_compressed,this);
00104     else
00105         rear_cam = n.subscribe("REAR/image_raw",10, &Ros::rear_camCallback,this);
00106     if(cameraFront_jpeg_compression)
00107         ptz_cam = n.subscribe("PTZ/image_raw/compressed",10, &Ros::ptz_camCallback_compressed,this);
00108     else
00109         ptz_cam = n.subscribe("PTZ/image_raw",10, &Ros::ptz_camCallback,this);
00110 
00111 
00112 
00113     kinect_selected = true;
00114     pan = 0;
00115     tilt = 0;
00116     timer = nh.createTimer(ros::Duration(2), &Ros::timerCallback, this);
00117     initialized = true;
00118 }
00119 
00120 void Ros::init(){
00121     int argc=0;
00122     char** argv= NULL;
00123     ros::init(argc, argv,"GUI");
00124   //  ros::start();
00125 
00126     this->subscribe();
00127     this->start();
00128 }
00129 
00130 //subscribe to only the camera topics we are interested in
00131 void Ros::currentCameraTabChanged(int index)
00132 {
00133     if (initialized == true)
00134     {
00135             ros::NodeHandle n;
00136             if(index == 0) // PTZ Camera
00137             {
00138                 if(cameraFront_jpeg_compression)
00139                     ptz_cam = n.subscribe("PTZ/image_raw/compressed",10, &Ros::ptz_camCallback_compressed,this);
00140                 else
00141                     ptz_cam = n.subscribe("PTZ/image_raw",10, &Ros::ptz_camCallback,this);
00142                 rear_cam.shutdown();
00143                 kinect_rgb.shutdown();
00144                 kinect_depth.shutdown();
00145             }
00146             else if(index == 1) // rear Camera
00147             {
00148                 if(cameraRear_jpeg_compression)
00149                     rear_cam = n.subscribe("REAR/image_raw/compressed",10, &Ros::rear_camCallback_compressed,this);
00150                 else
00151                     rear_cam = n.subscribe("REAR/image_raw",10, &Ros::rear_camCallback,this);
00152                 ptz_cam.shutdown();
00153                 kinect_rgb.shutdown();
00154                 kinect_depth.shutdown();
00155             }
00156             else if (index == 2)
00157             {
00158                 rear_cam.shutdown();
00159                 ptz_cam.shutdown();
00160                 kinect_rgb.shutdown();
00161                 kinect_depth.shutdown();
00162             }
00163             else if(index == 3) // Kinect RGB
00164             {
00165                 kinect_rgb = n.subscribe("/camera/rgb/image_color/compressed",100,&Ros::kinectrgbCallback,this);
00166                 rear_cam.shutdown();
00167                 ptz_cam.shutdown();
00168                 kinect_depth.shutdown();
00169             }
00170             else if(index == 4) // Kinect Depth
00171             {
00172                 kinect_depth = n.subscribe("/camera/depth/image",100,&Ros::kinectdepthCallback,this);
00173                 rear_cam.shutdown();
00174                 kinect_rgb.shutdown();
00175                 ptz_cam.shutdown();
00176             }
00177     }
00178 }
00179 
00180 void Ros::init(const std::string & master,const std::string & host){
00181                 std::map<std::string,std::string> remappings;
00182                 remappings["__master"] = master;
00183                 remappings["__ip"] = host;
00184                 ros::init(remappings,"GUI");
00185          //  ros::start();
00186 
00187                 this->subscribe();
00188                 this->start();
00189 }
00190 
00191 void Ros::setSpeedFast(bool toggled){
00192         if(toggled)
00193         {
00194                 speed_value = 100;
00195                 corobot_msgs::velocityValue msg;
00196                 msg.velocity = speed_value;
00197                 velocityValue_pub.publish(msg);
00198         }
00199 }
00200 void Ros::setSpeedModerate(bool toggled){
00201         if(toggled)
00202         {
00203                 speed_value = 75;
00204                 corobot_msgs::velocityValue msg;
00205                 msg.velocity = speed_value;
00206                 velocityValue_pub.publish(msg);
00207         }
00208 }
00209 void Ros::setSpeedSlow(bool toggled){
00210         if(toggled)
00211         {
00212                 speed_value = 50;
00213                 corobot_msgs::velocityValue msg;
00214                 msg.velocity = speed_value;
00215                 velocityValue_pub.publish(msg);
00216         }
00217 }
00218 
00219 void Ros::kinectdepthCallback(const sensor_msgs::Image::ConstPtr& msg){
00220     if(kinect_selected){
00221         unsigned char * copy;
00222         copy = (unsigned char*)malloc(msg->width*msg->height*3);
00223         float* tmp;
00224 
00225         for(int j=0;j<(msg->width*msg->height*3);j+=3){
00226             tmp = (float*)(&msg->data[0]+(j/3)*4);
00227             copy[j] = (char)((float)64*(float)(*tmp));
00228             copy[j+1] = (char)((float)64*(float)(*tmp));
00229             copy[j+2] = (char)((float)64*(float)(*tmp));
00230         }
00231 
00232     QImage *i = new QImage(copy,msg->width,msg->height,3*msg->width,QImage::Format_RGB888);
00233     QImage icopy = i->copy(0,0,msg->width,msg->height);
00234     if(i!=NULL){
00235             if(scenes_kinect_depth != NULL)
00236             {
00237 
00238                // scenes_kinect_depth->setBackgroundBrush(QBrush(i->copy(0,0,msg->width,msg->height)));
00239                 emit update_kinectDepthcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00240             }
00241         }
00242     free(copy);
00243     delete i;
00244 
00245 }
00246 }
00247 
00248 
00249 /*
00250   kinect hand gesture detection
00251 void Ros::kinectskelCallback(const body_msgs::Skeletons::ConstPtr& msg){
00252     if(kinect_selected){
00253     scenes_kinect_rgb->clear();
00254 
00255     if((msg->skeletons[0].left_hand.position.x - last_x_pos)>0.05)
00256         ROS_INFO("right");
00257     else if ((-msg->skeletons[0].left_hand.position.x + last_x_pos)>0.05)
00258          ROS_INFO("left");
00259     if((msg->skeletons[0].left_hand.position.y - last_y_pos)>0.05)
00260         ROS_INFO("up");
00261     else if ((-msg->skeletons[0].left_hand.position.y + last_y_pos)>0.05)
00262          ROS_INFO("down");corobot_teleop::SSC32NodeSetSpeed
00263     last_x_pos = msg->skeletons[0].left_hand.position.x;
00264     last_x_pos = msg->skeletons[0].left_hand.position.y;
00265 }
00266 }
00267 */
00268 void Ros::kinectrgbCallback(const sensor_msgs::CompressedImage::ConstPtr& msg){
00269     if(kinect_selected){
00270     QImage *i = new QImage();
00271     i->loadFromData(&msg->data[0],msg->data.size(),"JPEG");
00272     QImage icopy = i->scaled(640,480);
00273     if(i!=NULL){
00274             if(scenes_kinect_rgb != NULL)
00275             {
00276 
00277                 scenes_kinect_rgb->setSceneRect(0,0,640,480);
00278                 emit update_kinectRGBcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00279             }
00280         }
00281 
00282     delete i;
00283     }
00284 }
00285 void Ros::select_kinect(bool value){
00286     kinect_selected = value;
00287 }
00288 
00289 
00290 void Ros::velocityCallback(const nav_msgs::Odometry::ConstPtr& msg){
00291     double linear, angular;
00292     linear = sqrt(msg->twist.twist.linear.x *msg->twist.twist.linear.x + msg->twist.twist.linear.y * msg->twist.twist.linear.y);
00293     angular = msg->twist.twist.angular.z;
00294 
00295     emit velocity_info(linear,angular);
00296 
00297 }
00298 void Ros::irCallback(const corobot_msgs::IrMsg::ConstPtr& msg){
00299 
00300     double ir01, ir02;
00301 
00302     ir01 = (double)msg->range1;
00303     ir02 = (double)msg->range2;
00304 
00305     ROS_INFO("ir01 = %f", ir01);
00306     ROS_INFO("ir02 = %f\n", ir02);
00307 
00308     emit irData(ir01,ir02);
00309 
00310 }
00311 void Ros::powerCallback(const corobot_msgs::PowerMsgConstPtr& msg){
00312     //ROS_INFO("Got in power Callback!!");
00313     int percent;
00314     if(msg->volts>= 12)
00315         percent = 100;
00316     else
00317        percent = ((float)(msg->volts - BATTERY_EMPTY)/(float)(12-BATTERY_EMPTY))*100;
00318     emit battery_percent(percent);
00319     emit battery_volts((double)msg->volts);
00320 }
00321 void Ros::bumperCallback(const corobot_msgs::BumperMsg::ConstPtr& msg){
00322      emit bumper_update(msg->value0, msg->value1, msg->value2, msg->value3);
00323 }
00324 
00325 void Ros::gripperCallback(const corobot_msgs::GripperMsg::ConstPtr& msg){
00326     emit this->griperState(msg->state);
00327 }
00328 
00329 
00330 void Ros::cameraInfoCallback(const sensor_msgs::CameraInfo::ConstPtr& msg){
00331 
00332 }
00333 void Ros::cameraImageCallback(const sensor_msgs::Image::ConstPtr& msg){
00334 //    QImage *i = new QImage(&msg->data[0],msg->width,msg->height,msg->step,QImage::Format_RGB888);
00335 //    QImage icopy = i->copy(0,0,msg->width,msg->height);
00336 //    if(i!=NULL){
00337 //            if(scenes != NULL)
00338 //            {
00339 //                scenes->setSceneRect(0,0,msg->width,msg->height);
00340 //                image_camera.setCoroware_gui::Image(icopy);
00341 //            }
00342 
00343 //            if(scenes_all_cam !=NULL){
00344 //                *i=i->scaled(320,240);
00345 //                bottom_left.setImage(*i);
00346 //            }Mode
00347 //            emit update_alvoid Pan_control(int value);lcam()gpsCoroware_gui::;
00348 
00349 //        }gpsCoroware_gui::
00350 //    delete i;
00351 }
00352 
00353 void Ros::rear_camCallback(const sensor_msgs::Image::ConstPtr& msg){
00354     QImage *i = new QImage(&msg->data[0],msg->width,msg->height,msg->step,QImage::Format_RGB888);
00355     QImage icopy = i->copy(0,0,msg->width,msg->height);
00356 
00357     if(i!=NULL){
00358             if(scenes_rear_cam != NULL)
00359             {
00360                 //scenes_rear_cam->setSceneRect(0,0,msg->width,msg->height);
00361                 scenes_rear_cam->setSceneRect(0,0,640,480);
00362                 emit update_rearcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00363             }
00364         }
00365     delete i;
00366 }
00367 
00368 void Ros::rear_camCallback_compressed(const sensor_msgs::CompressedImage::ConstPtr& msg){
00369    // QImage *i = new QImage(&msg->data[0],msg->width,msg->height,msg->step,QImage::Format_RGB888);
00370    // QImage icopy = i->copy(0,0,msg->width,msg->height);
00371 
00372     QImage *i = new QImage();
00373     i->loadFromData(&msg->data[0],msg->data.size(),"JPEG");
00374     //icopy = i->copy(0,0,msg->width,msg->height);
00375     QImage icopy = i->copy(0,0,640,480);
00376     if(i!=NULL){
00377             if(scenes_rear_cam != NULL)
00378             {
00379                 //scenes_rear_cam->setSceneRect(0,0,msg->width,msg->height);
00380                 scenes_rear_cam->setSceneRect(0,0,640,480);
00381                 emit update_rearcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00382             }
00383         }
00384     delete i;
00385 }
00386 
00387 void Ros::ptz_camCallback(const sensor_msgs::Image::ConstPtr& msg){
00388     QImage *i = new QImage(&msg->data[0],msg->width,msg->height,msg->step,QImage::Format_RGB888);
00389     QImage icopy = i->copy(0,0,msg->width,msg->height);
00390 
00391     if(i!=NULL){
00392             if(scenes_ptz_cam != NULL)
00393             {
00394                 //scenes_ptz_cam->setSceneRect(0,0,msg->width,msg->height);
00395                 scenes_ptz_cam->setSceneRect(0,0,640,480);
00396                 emit update_ptzcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00397             }
00398 
00399         }
00400     delete i;
00401 }
00402 
00403 void Ros::ptz_camCallback_compressed(const sensor_msgs::CompressedImage::ConstPtr& msg){
00404   //  QImage *i = new QImage(&msg->data[0],msg->width,msg->height,msg->step,QImage::Format_RGB888);
00405    // QImage icopy = i->copy(0,0,msg->width,msg->height);
00406 
00407     QImage *i = new QImage();
00408     i->loadFromData(&msg->data[0],msg->data.size(),"JPEG");
00409    // icopy = i->copy(0,0,msg->width,msg->height);
00410     QImage icopy = i->copy(0,0,640,480);
00411     if(i!=NULL){
00412             if(scenes_ptz_cam != NULL)
00413             {
00414                 //scenes_ptz_cam->setSceneRect(0,0,msg->width,msg->height);
00415                 scenes_ptz_cam->setSceneRect(0,0,640,480);
00416                 emit update_ptzcam(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00417             }
00418         }
00419     delete i;
00420 }
00421 
00422 void Ros::mapCallback(const sensor_msgs::CompressedImage::ConstPtr& msg){
00423     QImage *i = new QImage();
00424     i->loadFromData(&msg->data[0],msg->data.size(),"JPEG");
00425     QImage icopy = i->copy(0,0,i->height(),i->width());
00426     if(i!=NULL){
00427             if(scenes_map_image != NULL)
00428             {
00429           //       scenes_map_image->setSceneRect(0,0,msg->width,msg->height);
00430                 scenes_rear_cam->setSceneRect(0,0,i->height(),i->width());
00431                 emit update_mapimage(icopy); //we can't allow a thread to use the scene for the zoom and another one to modify the image as it would crash, so we do everything in one thread
00432             }
00433         }
00434     delete i;
00435 }
00436 
00437 void Ros::gpsCallback(const sensor_msgs::NavSatFix::ConstPtr& msg){
00438     double lat = msg->latitude;
00439     double lon = msg->longitude;
00440 
00441     //ROS_INFO("GUI has received latitude =  %f  and  longtitude =  %f \n",lat,lon);
00442 
00443     //if(msg->status.status != 0)
00444     //{
00445         emit gps_lat(lat);
00446         emit gps_lon(lon);
00447         emit gps_coord(lat,lon);
00448     //}
00449 }
00450 void Ros::scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg){
00451 
00452 //convert from (angle,range) into (x,y)
00453 
00454     //vector<qrk::Point<long> > points;
00455 
00456       int index = 0;
00457 /*      for (vector<float>::const_iterator it = 44;/*msg->ranges.begin();*/
00458            //it != 726;/*msg->ranges.end();*/ ++it, ++index) */
00459 
00460       for(int it = 44; it<726; it++)
00461       {
00462 //        long distance = msg->ranges[it];
00463 //        if ((distance <= msg->range_min) || (distance >= msg->range_max)) {
00464 //          continue;
00465 //        }
00466 
00467 //        double radian = msg->angle_min +msg->angle_increment*index  + M_PI/2;
00468 //        long x = static_cast<long>(distance * cos(radian));
00469 //        long y = static_cast<long>(distance * sin(radian));
00470 
00471 //        points.push_back(qrk::Point<long>(x, y));
00472 
00473           hokuyo_points_[it-44].distance = msg->ranges[it];
00474           hokuyo_points_[it-44].angle_step = msg->angle_increment;
00475           hokuyo_points_[it-44].index = it - 44;
00476 
00477           double radian = (index - 384 + 44) * msg->angle_increment;
00478                   //msg->angle_min +msg->angle_increment*it;// + M_PI/2;
00479           //cos (radian);
00480           //sin (radian);
00481 
00482           hokuyo_points_[it-44].x = -(hokuyo_points_[it-44].distance * sin (radian)); //(long)(distance* cos (radian));
00483           hokuyo_points_[it-44].y = hokuyo_points_[it-44].distance * cos (radian); //(long)(distance* sin (radian));
00484 
00485           index ++;
00486 
00487       }
00488       //ROS_INFO("Recieved one set of /scan data!! %d", index );
00489       //rangeWidget.setUrgData(points,msg->header.stamp.toSec());
00490       //rangeWidget2.setUrgData(points,msg->header.stamp.toSec());
00491 
00492       emit hokuyo_update(hokuyo_points_);
00493 
00494 }
00495 
00496 void Ros::ssc32infoCallback(const corobot_msgs::ssc32_info::ConstPtr &msg)
00497 {
00498     if(msg->connected == 1)
00499         ROS_INFO("SSC32 is successfully connectted");
00500     else ROS_INFO("SSC32 failed to connect");
00501 
00502 }
00503 
00504 void Ros::phidgetinfoCallback(const corobot_msgs::phidget_info::ConstPtr &msg)
00505 {
00506     if(msg->phidget888_connected == 1)
00507         ROS_INFO("phidget 888 is successfully connectted");
00508     else ROS_INFO("phidget 888 failed to connect");
00509 
00510     if(msg->phidget_encoder_connected == 1)
00511         ROS_INFO("phidget encoder is successfully connectted");
00512     else ROS_INFO("phidget encoder failed to connect");
00513 }
00514 
00515 void Ros::takepicCallback(const corobot_msgs::takepic::ConstPtr &msg)
00516 {
00517     if(msg->take)
00518     {
00519         image_ptz_cam.saveImage();
00520     }
00521 }
00522 
00523 void Ros::run(){
00524     ros::spin();
00525 }
00526 
00527 void Ros::spatialCallback(const corobot_msgs::spatial::ConstPtr &msg)
00528 {
00529     double acc_x, acc_y, acc_z, ang_x, ang_y, ang_z, mag_x, mag_y, mag_z;
00530 
00531     acc_x = (double)msg->acc1;
00532     acc_y = (double)msg->acc2;
00533     acc_z = (double)msg->acc3;
00534     ang_x = (double)msg->ang1;
00535     ang_y = (double)msg->ang2;
00536     ang_z = (double)msg->ang3;
00537     mag_x = (double)msg->mag1;
00538     mag_y = (double)msg->mag2;
00539     mag_z = (double)msg->mag3;
00540 
00541     emit spatial_data(acc_x,acc_y,acc_z,ang_x,ang_y,ang_z,mag_x,mag_y,mag_z);
00542 }
00543 
00544 void Ros::moveGripper(bool state){
00545     if(state)
00546         Ros::openGripper();
00547     else
00548         Ros::closeGripper();
00549 }
00550 
00551 void Ros::add_camera_info_scene(QGraphicsScene * scene){
00552 //        scenes = scene;
00553 //        scenes->setSceneRect(0,0,640,480);
00554 //        image_camera.setPos(0,0);
00555 //        scenes->addItem(&image_camera);
00556 }
00557 
00558 
00559 void Ros::add_rear_cam_scene(QGraphicsScene * scene){
00560         scenes_rear_cam = scene;
00561         scenes_rear_cam->setSceneRect(0,0,640,480);
00562         image_rear_cam.setPos(0,0);
00563         scenes_rear_cam->addItem(&image_rear_cam);
00564 }
00565 
00566 void Ros::add_map_image_scene(QGraphicsScene * scene){
00567         scenes_map_image = scene;
00568         scenes_map_image->setSceneRect(0,0,2048,2048);
00569         image_map_image.setPos(0,0);
00570         scenes_map_image->addItem(&image_map_image);
00571 }
00572 
00573 void Ros::add_front_image_scene(QGraphicsScene * scene){
00574         scenes_front_image = scene;
00575         scenes_front_image->setSceneRect(0,0,640,480);
00576         image_front_cam.setPos(0,0);
00577         scenes_front_image->addItem(&image_front_cam);
00578 }
00579 
00580 void Ros::add_ptz_cam_scene(QGraphicsScene * scene){
00581         scenes_ptz_cam = scene;
00582         scenes_ptz_cam->setSceneRect(0,0,640,480);
00583         image_ptz_cam.setPos(0,0);
00584         scenes_ptz_cam->addItem(&image_ptz_cam);
00585 }
00586 
00587 void Ros::add_kinect_rgb_scene(QGraphicsScene * scene){
00588         scenes_kinect_rgb = scene;
00589         scenes_kinect_rgb->setSceneRect(0,0,640,480);
00590         image_kinect_rgb.setPos(0,0);
00591         scenes_kinect_rgb->addItem(&image_kinect_rgb);
00592 }
00593 
00594 
00595 
00596 void Ros::add_kinect_depth_scene(QGraphicsScene *scene){
00597     scenes_kinect_depth = scene;
00598     scenes_kinect_depth->setSceneRect(0,0,640,480);
00599     image_kinect_depth.setPos(0,0);
00600     scenes_kinect_depth->addItem(&image_kinect_depth);
00601 
00602 }
00603 
00604 
00605 
00606 
00607 
00608 void Ros::corobot(bool value){
00609     Corobot = value;
00610 }
00611 
00612 
00613 bool Ros::setOdom(float x, float y){
00614     corobot_srvs::SetOdom srv1;
00615 
00616     srv1.request.px = x;
00617     srv1.request.py = y;
00618 
00619     return(this->setOdom_client.call(srv1) && srv1.response.err ==0);
00620 }
00621 
00622 
00623 
00624 
00625 void Ros::turnWrist(float angle){
00626 
00627         if(moveArm_pub)
00628         {
00629             corobot_msgs::MoveArm msg;
00630 
00631             /* Do some angle conversions. First we add PI/2 because the default position is actually at angle Pi/2. 
00632                Then we make sure that the angle is not too high or too low
00633                 Finally we convert to a value in degrees
00634             */
00635             double temp = -angle + M_PI/2;
00636             if  (-angle > M_PI)
00637                 temp =  - 2*M_PI - angle + M_PI/2;
00638             if (temp < 0)
00639                 temp = 2*M_PI + temp;
00640             if(0 < temp || temp > M_PI)
00641                 temp = (double)((int)(temp * 180/M_PI) % 180); // execute temp % M_PI, the conversion to int in degree is necessary as the modulus works with integers.
00642 
00643 
00644                 //temporarily move both the flex and rotation see the GUI doesn't do the difference
00645             msg.index = msg.WRIST_FLEX;
00646             msg.position = temp;
00647 
00648             moveArm_pub.publish(msg);
00649 
00650             msg.index = msg.WRIST_ROTATION;
00651             msg.position = temp;
00652 
00653             moveArm_pub.publish(msg);
00654         }
00655 }
00656 
00657 void Ros::openGripper(){
00658 
00659         if(moveArm_pub)
00660         {
00661                 corobot_msgs::MoveArm msg;
00662 
00663                 msg.index = msg.GRIPPER;
00664                 msg.position = 0;
00665 
00666                 moveArm_pub.publish(msg);
00667         }
00668 }
00669 
00670 void Ros::closeGripper(){
00671 
00672         if(moveArm_pub)
00673         {
00674                 corobot_msgs::MoveArm msg;
00675 
00676                 msg.index = msg.GRIPPER;
00677                 msg.position = 180;
00678 
00679                 moveArm_pub.publish(msg);
00680         }
00681 }
00682 
00683 
00684 bool Ros::setCameraControl(int id, int value){
00685  /*    dynamic_uvc_cam::sResetOdometcontrol srv1;
00686      srv1.request.id = id;
00687      srv1.request.value = value;
00688 
00689      return(this->setCameraControl_client.call(srv1));*/
00690     return true;
00691 }
00692 
00693 
00694 bool Ros::setCameraState(bool state){
00695   /*  dynamic_uvc_cam::state msg1;
00696     if(state)
00697         msg1.state = "start";
00698     else
00699         msg1.state = "stop";
00700 
00701     this->cameraStatePub.publish(msg1);
00702 
00703     return true;*/return true;
00704 }
00705 
00706 bool Ros::setCameraMode(int width, int weight, bool immediately, int fps, bool auto_exposure)
00707 {
00708 
00709   /*  dynamic_uvc_cam::videomode msg1;
00710      msg1.width = width;
00711      msg1.height = weight;
00712      msg1.immediately = immediately;
00713      msg1.fps = fps;
00714      msg1.auto_exposure = auto_exposure;
00715 
00716 
00717      this->cameraModePub.publish(msg1);
00718      return true;*/
00719     return true;
00720 }
00721 
00722 void Ros::timerCallback(const ros::TimerEvent& event)
00723 {
00724         corobot_msgs::MotorCommand msg;
00725 
00726         msg.leftSpeed = speed_left;
00727         msg.rightSpeed = speed_right;
00728         msg.secondsDuration = 3;
00729         msg.acceleration = 50;
00730 
00731         driveControl_pub.publish(msg);
00732  
00733 }
00734 
00735 //Decrease speed when no robot movement buttons or key is pressed
00736 bool Ros::decrease_speed()
00737 {
00738     if(driveControl_pub)
00739     {
00740 
00741         corobot_msgs::MotorCommand msg;
00742 
00743         if(turningLeft)
00744         {
00745             speed_left = -speed_value;
00746             speed_right = speed_value;
00747         }
00748         else if(turningRight)
00749         {
00750             speed_left = speed_value;
00751             speed_right = -speed_value;
00752         }
00753         else
00754         {
00755             speed_left = 0;
00756             speed_right = 0;
00757         }
00758 
00759         msg.leftSpeed = speed_left;
00760         msg.rightSpeed = speed_right;
00761         msg.secondsDuration = 3;
00762         msg.acceleration = 50;
00763 
00764         driveControl_pub.publish(msg);
00765 
00766     }
00767     return true;
00768 }
00769 
00770 //Increase speed when the move forward button or key is pressed
00771 bool Ros::increase_speed()
00772 {
00773 
00774     corobot_msgs::MotorCommand msg;
00775         if(driveControl_pub)
00776         {
00777                         speed_left += speed_value;
00778                         speed_right += speed_value;
00779 
00780                         if(speed_left >speed_value)
00781                                 speed_left = speed_value;
00782                         if(speed_right >speed_value)
00783                                 speed_right = speed_value;
00784                         msg.leftSpeed = speed_left;
00785                         msg.rightSpeed = speed_right;
00786                         msg.secondsDuration = 3;
00787                         msg.acceleration = 50;
00788 
00789 
00790                     driveControl_pub.publish(msg);
00791                 return true;
00792         }
00793         else
00794                 return false;
00795 }
00796 
00797 //Increase speed when the move backward button or key is pressed
00798 bool Ros::increase_backward_speed()
00799 {
00800     corobot_msgs::MotorCommand msg;
00801         if(driveControl_pub)
00802         {
00803                 speed_left -= speed_value;
00804                 speed_right -= speed_value;
00805 
00806                 if(speed_left <-speed_value)
00807                         speed_left = -speed_value;
00808                 if(speed_right <-speed_value)
00809                         speed_right = -speed_value;
00810 
00811                 msg.leftSpeed = speed_left;
00812                 msg.rightSpeed = speed_right;
00813                 msg.secondsDuration = 3;
00814                 msg.acceleration = 50;
00815 
00816                 driveControl_pub.publish(msg);
00817                 return true;
00818         }
00819         else
00820                 return false;
00821 }
00822 
00823 bool Ros::turn_left()
00824 {
00825     corobot_msgs::MotorCommand msg;
00826 
00827         if(driveControl_pub)
00828         {
00829                 if((speed_left+speed_right)<0)
00830                 {
00831                     speed_left += speed_value;
00832                     speed_right -= speed_value;
00833                 }
00834                 else
00835                 {
00836                     speed_left -= speed_value;
00837                     speed_right += speed_value;
00838                 }
00839 
00840                 if(speed_left >speed_value)
00841                     speed_left = speed_value;
00842                 if(speed_right >speed_value)
00843                     speed_right = speed_value;
00844                 if(speed_left <-speed_value)
00845                     speed_left = -speed_value;
00846                 if(speed_right <-speed_value)
00847                     speed_right = -speed_value;
00848 
00849 
00850                 msg.leftSpeed = speed_left;
00851                 msg.rightSpeed = speed_right;
00852                 msg.secondsDuration = 3;
00853                 msg.acceleration = 50;
00854 
00855                 driveControl_pub.publish(msg);
00856                 turningLeft = true;
00857                 turningRight = false;
00858                 return true;
00859         }
00860         else
00861                 return false;
00862 }
00863 
00864 bool Ros::turn_right()
00865 {
00866     corobot_msgs::MotorCommand msg;
00867 
00868         if(driveControl_pub)
00869         {
00870                 if((speed_left+speed_right)<0)
00871                 {
00872                     speed_left -= speed_value;
00873                     speed_right += speed_value;
00874                 }
00875                 else
00876                 {
00877                     speed_left += speed_value;
00878                     speed_right -= speed_value;
00879                 }
00880                 if(speed_left >speed_value)
00881                     speed_left = speed_value;
00882                 if(speed_right >speed_value)
00883                     speed_right = speed_value;
00884                 if(speed_left <-speed_value)
00885                     speed_left = -speed_value;
00886                 if(speed_right <-speed_value)
00887                     speed_right = -speed_value;
00888 
00889                 msg.leftSpeed = speed_left;
00890                 msg.rightSpeed = speed_right;
00891                 msg.secondsDuration = 3;
00892                 msg.acceleration = 50;
00893 
00894                 driveControl_pub.publish(msg);
00895                 turningRight = true;
00896                 turningLeft = false;
00897                 return true;
00898         }
00899         else
00900                 return false;
00901 }
00902 
00903 bool Ros::stop_turn()
00904 {
00905     corobot_msgs::MotorCommand msg;
00906 
00907         if(driveControl_pub)
00908         {       
00909                 if((speed_left+speed_right)<0)
00910                 {
00911                         speed_left = -speed_value;
00912                         speed_right = -speed_value;
00913                 }
00914                 else if((speed_left+speed_right)>0)
00915                 {
00916                         speed_left = +speed_value;
00917                         speed_right = +speed_value;
00918                 }
00919                 else
00920                 {
00921                         speed_left = 0;
00922                         speed_right = 0;
00923                 }
00924         
00925                 msg.leftSpeed = speed_left;
00926                 msg.rightSpeed = speed_right;
00927                 msg.secondsDuration = 3;
00928                 msg.acceleration = 50;
00929 
00930                 driveControl_pub.publish(msg);
00931                 turningLeft = false;
00932                 turningRight = false;
00933                 return true;
00934         }
00935         else
00936                 return false;
00937 }
00938 
00939 
00940 bool Ros::motor_stop()
00941 {
00942     corobot_msgs::MotorCommand msg;
00943 
00944         if(driveControl_pub)
00945         {
00946                 msg.leftSpeed = 0;
00947                 msg.rightSpeed = 0;
00948                 msg.secondsDuration = 0;
00949                 msg.acceleration = 50;
00950                 driveControl_pub.publish(msg);
00951                 return true;
00952         }
00953         else
00954                 return false;
00955 }
00956 
00957 
00958 void Ros::moveShoulderArm(double shoulder)
00959 {
00960         if(moveArm_pub)
00961         {
00962                 corobot_msgs::MoveArm msg;
00963 
00964                 msg.index = msg.SHOULDER;
00965                 msg.position = shoulder *180/M_PI; //convertion from radian to degree
00966 
00967                 moveArm_pub.publish(msg);
00968         }
00969 }
00970 
00971 void Ros::moveElbowArm(double elbow)
00972 {
00973         if(moveArm_pub)
00974         {
00975                 corobot_msgs::MoveArm msg;
00976 
00977                 msg.index = msg.ELBOW;
00978                 msg.position = elbow *180/M_PI; //convertion from radian to degree
00979 
00980                 moveArm_pub.publish(msg);
00981         }
00982 }
00983 
00984 void Ros::rotateArm(double angle)
00985 {
00986         if(moveArm_pub)
00987         {
00988                 corobot_msgs::MoveArm msg;
00989 
00990                 msg.index = msg.BASE_ROTATION;
00991                 msg.position = angle *181/M_PI; //convertion from radian to degree
00992 
00993                 moveArm_pub.publish(msg);
00994         }
00995 }
00996 
00997 void Ros::ResetArm()
00998 {
00999         if(moveArm_pub)
01000         {
01001                 corobot_msgs::MoveArm msg;
01002 
01003                 msg.index = msg.SHOULDER;
01004                 msg.position = 0;
01005                 moveArm_pub.publish(msg);
01006 
01007                 msg.index = msg.ELBOW;
01008                 msg.position = 0; 
01009                 moveArm_pub.publish(msg);
01010 
01011                 msg.index = msg.WRIST_FLEX;
01012                 msg.position = 90; 
01013                 moveArm_pub.publish(msg);
01014 
01015                 msg.index = msg.WRIST_ROTATION;
01016                 msg.position = 90; 
01017                 moveArm_pub.publish(msg);
01018 
01019                 msg.index = msg.GRIPPER;
01020                 msg.position = 0; 
01021                 moveArm_pub.publish(msg);
01022 
01023                 msg.index = msg.BASE_ROTATION;
01024                 msg.position = 90; 
01025                 moveArm_pub.publish(msg);
01026         }
01027 }


corobot_teleop
Author(s): Morgan Cormier/Gang Li/mcormier@coroware.com
autogenerated on Tue Jan 7 2014 11:39:41