00001 /*!@file src/Robots/Scorobt/move-Scorbot.C Move the robot in varius ways */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/Scorbot/move-Scorbot.C $ 00035 // $Id: move-Scorbot.C 14059 2010-09-28 02:13:59Z rand $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Devices/Scorbot.H" 00040 #include "Util/MathFunctions.H" 00041 #include "Util/Types.H" 00042 #include "Util/log.H" 00043 #include "Media/FrameSeries.H" 00044 #include "Transport/FrameInfo.H" 00045 #include "Raster/GenericFrame.H" 00046 #include "GUI/XWinManaged.H" 00047 #include "GUI/ImageDisplayStream.H" 00048 #include "GUI/PrefsWindow.H" 00049 #include "Image/DrawOps.H" 00050 #include <unistd.h> 00051 #include <stdio.h> 00052 #include <signal.h> 00053 00054 nub::soft_ref<Scorbot> scorbot; 00055 //Sholder 3000 - -7000 00056 //ex1: -20000 - -150000 00057 //sholder: 00058 void terminate(int s) 00059 { 00060 LINFO("*** INTERRUPT ***"); 00061 scorbot->stopAllMotors(); 00062 scorbot->motorsOff(); 00063 sleep(1); 00064 exit(0); 00065 } 00066 00067 00068 int main(int argc, char **argv) 00069 { 00070 // Instantiate a ModelManager: 00071 ModelManager manager("Move Robot"); 00072 00073 scorbot = nub::soft_ref<Scorbot>(new Scorbot(manager)); 00074 manager.addSubComponent(scorbot); 00075 00076 // catch signals and redirect them to terminate for clean exit: 00077 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00078 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00079 signal(SIGALRM, terminate); 00080 00081 // Grab the first command line option, and then wipe it out. The manager can't see any 00082 // options after this. 00083 if(argc != 3) 00084 { 00085 std::cerr << "TIME POSITION" << std::endl; 00086 exit(0); 00087 } 00088 int time = atoi(argv[1]); 00089 int pos = atoi(argv[2]); 00090 std::cerr << "TIME: " << time << std::endl; 00091 std::cerr << "POS: " << pos << std::endl; 00092 argv[1] = 0; 00093 00094 // Parse command-line: 00095 if (manager.parseCommandLine(1, argv, "", 0, 0) == false) return(1); 00096 00097 // let's get all our ModelComponent instances started: 00098 manager.start(); 00099 00100 00101 00102 00103 // ###################################################################### 00104 //PID TESTING 00105 Scorbot::ArmPos armPos; 00106 00107 scorbot->resetEncoders(); 00108 armPos.base = 0; 00109 armPos.sholder = 0; 00110 armPos.elbow = 0; 00111 armPos.wrist1 = 0; 00112 armPos.wrist2 = 0; 00113 armPos.gripper = 0; 00114 armPos.ex1 = 0; 00115 armPos.duration = 1; 00116 if(!scorbot->setArmPos(armPos)) 00117 LFATAL("Unable to set position"); 00118 00119 usleep(100000); 00120 scorbot->motorsOn(); 00121 sleep(1); 00122 00123 scorbot->clearBuffer(); 00124 00125 while(1) 00126 { 00127 scorbot->motorsOn(); 00128 00129 armPos.base = 0; 00130 armPos.sholder = 0; 00131 armPos.elbow = 0; 00132 armPos.wrist1 = 0; 00133 armPos.wrist2 = 0; 00134 armPos.gripper = 0; 00135 armPos.ex1 = pos; 00136 armPos.duration = time; 00137 if(!scorbot->setArmPos(armPos)) 00138 LFATAL("Unable to set position"); 00139 00140 sleep(time/100+2); 00141 00142 long time, posErr, desiredPos, desiredVel, encoderVal, pwm; 00143 scorbot->getJointParams(Scorbot::EX1, time, posErr, desiredPos, desiredVel, encoderVal, pwm); 00144 printf("%li\n", 00145 encoderVal); 00146 sleep(1); 00147 00148 armPos.base = 0; 00149 armPos.sholder = 0; 00150 armPos.elbow = 0; 00151 armPos.wrist1 = 0; 00152 armPos.wrist2 = 0; 00153 armPos.gripper = 0; 00154 armPos.ex1 = 0; 00155 armPos.duration = time; 00156 if(!scorbot->setArmPos(armPos)) 00157 LFATAL("Unable to set position"); 00158 00159 sleep(time/100+2); 00160 00161 scorbot->getJointParams(Scorbot::EX1, time, posErr, desiredPos, desiredVel, encoderVal, pwm); 00162 printf("%li\n", 00163 encoderVal); 00164 sleep(1); 00165 00166 } 00167 00168 00169 00170 armPos.base = 0; 00171 armPos.sholder = 0; 00172 armPos.elbow = 0; 00173 armPos.wrist1 = 0; 00174 armPos.wrist2 = 0; 00175 armPos.gripper = 0; 00176 armPos.ex1 = pos; 00177 armPos.duration = time; 00178 if(!scorbot->setArmPos(armPos)) 00179 LFATAL("Unable to set position"); 00180 00181 int i=0; 00182 while(1) 00183 { 00184 long time, posErr, desiredPos, desiredVel, encoderVal, pwm; 00185 scorbot->getJointParams(Scorbot::EX1, time, posErr, desiredPos, desiredVel, encoderVal, pwm); 00186 00187 printf("%i %li %li %li %li %li %li\n", 00188 i++, time, posErr, desiredPos, desiredVel, encoderVal, pwm); 00189 usleep(10000); 00190 } 00191 // ###################################################################### 00192 00193 00194 //scorbot->motorsOn(); 00195 //sleep(1); 00196 //scorbot->clearBuffer(); 00197 //Scorbot::ArmPos armPos; 00198 //while(1) 00199 //{ 00200 // LINFO("POS 1"); 00201 // armPos.base = 10585 ; 00202 // armPos.sholder = -102; 00203 // armPos.elbow = 9456; 00204 // armPos.wrist1 = -2566; 00205 // armPos.wrist2 = 2260; 00206 // armPos.gripper = 0; 00207 // armPos.ex1 = -79790; 00208 // armPos.duration = 1000; 00209 // if(!scorbot->setArmPos(armPos)) 00210 // LFATAL("Unable to set position"); 00211 // sleep(5); 00212 00213 // LINFO("POS 2"); 00214 // armPos.base = 13010; 00215 // armPos.sholder = -6955; 00216 // armPos.elbow = 9136; 00217 // armPos.wrist1 = -3108; 00218 // armPos.wrist2 = 2596; 00219 // armPos.gripper = 0; 00220 // armPos.ex1 = 19841; 00221 // armPos.duration = 1000; 00222 // if(!scorbot->setArmPos(armPos)) 00223 // LFATAL("Unable to set position"); 00224 // sleep(5); 00225 00226 // LINFO("POS 3"); 00227 // armPos.base = 10584; 00228 // armPos.sholder = 2669; 00229 // armPos.elbow = 1027; 00230 // armPos.wrist1 = 678; 00231 // armPos.wrist2 = -997; 00232 // armPos.gripper = 0; 00233 // armPos.ex1 = -82987; 00234 // armPos.duration = 1000; 00235 // if(!scorbot->setArmPos(armPos)) 00236 // LFATAL("Unable to set position"); 00237 // sleep(5); 00238 00239 00240 //} 00241 00242 // for(uint i=0; i<15; i++) 00243 // { 00244 // //long time, desiredPos, desiredVel, encoderVal, pwm; 00245 // //scorbot->getJointParams(RobotArm::EX1, time, desiredPos, desiredVel, encoderVal, pwm); 00246 // //printf("%i %li %li %li %li %li\n",i, time, desiredPos, desiredVel, encoderVal, pwm); 00247 // Scorbot::ArmPos armPos = scorbot->getArmPos(); 00248 // 00249 // printf("%i %i %i %li %li %li %li %li %li %li %li\n", i, 00250 // 4500, 122500, 00251 // armPos.base, armPos.sholder, armPos.elbow, armPos.wrist1, armPos.wrist2, 00252 // armPos.gripper, armPos.ex1, armPos.ex2); 00253 // usleep(500000); 00254 // } 00255 // 00256 // LINFO("Go to position -4500 18000"); 00257 // armPos.base = -4500; 00258 // armPos.sholder = 0; 00259 // armPos.elbow = 0; 00260 // armPos.wrist1 = 0; 00261 // armPos.wrist2 = 0; 00262 // armPos.gripper = 0; 00263 // armPos.ex1 = 0; 00264 // armPos.duration = 1000; 00265 // if(!scorbot->setArmPos(armPos)) 00266 // LFATAL("Unable to set position"); 00267 // 00268 // for(uint i=0; i<15; i++) 00269 // { 00270 // //long time, desiredPos, desiredVel, encoderVal, pwm; 00271 // //scorbot->getJointParams(RobotArm::EX1, time, desiredPos, desiredVel, encoderVal, pwm); 00272 // //printf("%i %li %li %li %li %li\n",i, time, desiredPos, desiredVel, encoderVal, pwm); 00273 // Scorbot::ArmPos armPos = scorbot->getArmPos(); 00274 // 00275 // printf("%i %i %i %li %li %li %li %li %li %li %li\n", i, 00276 // 4500, 122500, 00277 // armPos.base, armPos.sholder, armPos.elbow, armPos.wrist1, armPos.wrist2, 00278 // armPos.gripper, armPos.ex1, armPos.ex2); 00279 // usleep(500000); 00280 // } 00281 // 00282 // } 00283 00284 //for(int pwm=0; pwm>-100; pwm--) 00285 ////for(int pwm=0; pwm<100; pwm++) 00286 //{ 00287 // if (scorbot->setMotor(RobotArm::EX1, pwm)) 00288 // { 00289 // for(uint i=0; i<10; i++) 00290 // { 00291 // Scorbot::ArmPos armPos = scorbot->getArmPos(); 00292 00293 // LINFO("b:%li s:%li e:%li g:%li e1:%li e2:%li duration: %li", 00294 // armPos.base, armPos.sholder, armPos.elbow, armPos.gripper, 00295 // armPos.ex1, armPos.ex2, armPos.duration); 00296 // printf("%i %ld\n", pwm, armPos.ex1); 00297 // } 00298 // } 00299 //} 00300 //scorbot->setMotor(RobotArm::BASE, 0); 00301 00302 00303 scorbot->motorsOff(); 00304 // stop all our ModelComponents 00305 manager.stop(); 00306 00307 // all done! 00308 return 0; 00309 } 00310 00311 00312 // ###################################################################### 00313 /* So things look consistent in everyone's emacs... */ 00314 /* Local Variables: */ 00315 /* indent-tabs-mode: nil */ 00316 /* End: */