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 #include <termios.h>
00034 #include <signal.h>
00035 #include <math.h>
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038
00039 #include <ros/ros.h>
00040 #include <geometry_msgs/Twist.h>
00041
00042 #include <ias_drawer_executive/RobotArm.h>
00043 #include <ias_drawer_executive/Gripper.h>
00044
00045 #define KEYCODE_A 0x61
00046 #define KEYCODE_D 0x64
00047 #define KEYCODE_S 0x73
00048 #define KEYCODE_W 0x77
00049 #define KEYCODE_Q 0x71
00050 #define KEYCODE_E 0x65
00051 #define KEYCODE_R 0x72
00052
00053 #define KEYCODE_I 0x69
00054 #define KEYCODE_K 0x6B
00055 #define KEYCODE_J 0x6A
00056 #define KEYCODE_L 0x6C
00057 #define KEYCODE_N 0x6E
00058 #define KEYCODE_M 0x6D
00059
00060 #define KEYCODE_I_CAP 0x49
00061 #define KEYCODE_K_CAP 0x4B
00062 #define KEYCODE_J_CAP 0x4A
00063 #define KEYCODE_L_CAP 0x4C
00064 #define KEYCODE_N_CAP 0x4E
00065 #define KEYCODE_M_CAP 0x4D
00066
00067 #define KEYCODE_A_CAP 0x41
00068 #define KEYCODE_D_CAP 0x44
00069 #define KEYCODE_S_CAP 0x53
00070 #define KEYCODE_W_CAP 0x57
00071 #define KEYCODE_Q_CAP 0x51
00072 #define KEYCODE_E_CAP 0x45
00073
00074 #define KEYCODE_BRACK_OP 0x5B
00075 #define KEYCODE_BRACK_CL 0x5D
00076
00077 class TeleopPR2Keyboard
00078 {
00079 private:
00080 double walk_vel, run_vel, yaw_rate, yaw_rate_run;
00081 geometry_msgs::Twist cmd;
00082
00083 ros::NodeHandle n_;
00084 ros::Publisher vel_pub_;
00085
00086 RobotArm *arm_;
00087 Gripper *gripper_;
00088
00089 public:
00090 void init(int arm_no)
00091 {
00092 cmd.linear.x = cmd.linear.y = cmd.angular.z = 0;
00093
00094 arm_ = RobotArm::getInstance(arm_no);
00095 gripper_ = Gripper::getInstance(arm_no);
00096
00097
00098
00099 ros::NodeHandle n_private("~");
00100 n_private.param("walk_vel", walk_vel, 0.5);
00101 n_private.param("run_vel", run_vel, 1.0);
00102 n_private.param("yaw_rate", yaw_rate, 1.0);
00103 n_private.param("yaw_run_rate", yaw_rate_run, 1.5);
00104
00105 }
00106
00107 ~TeleopPR2Keyboard() { }
00108 void keyboardLoop();
00109
00110 };
00111
00112 int kfd = 0;
00113 struct termios cooked, raw;
00114
00115 void quit(int sig)
00116 {
00117 tcsetattr(kfd, TCSANOW, &cooked);
00118 exit(0);
00119 }
00120
00121 int main(int argc, char** argv)
00122 {
00123
00124 char name[50] = "pr2_base_keyboard";
00125
00126 int no_arm = 0;
00127
00128 if (argc > 1)
00129 {
00130 no_arm = atoi(argv[1]);
00131 sprintf(name,"pr2_base_keyboard_%i",no_arm);
00132 }
00133
00134 ros::init(argc, argv, name);
00135
00136 ROS_INFO("INITIATLIZED NODE WITH NAME: %s", name);
00137
00138 TeleopPR2Keyboard tpk;
00139 tpk.init(no_arm);
00140
00141 signal(SIGINT,quit);
00142
00143 tpk.keyboardLoop();
00144
00145 return(0);
00146 }
00147
00148
00149 void TeleopPR2Keyboard::keyboardLoop()
00150 {
00151 char c;
00152 bool dirty=false;
00153 bool grip_dirty = false;
00154
00155
00156 tcgetattr(kfd, &cooked);
00157 memcpy(&raw, &cooked, sizeof(struct termios));
00158 raw.c_lflag &=~ (ICANON | ECHO);
00159
00160 raw.c_cc[VEOL] = 1;
00161 raw.c_cc[VEOF] = 2;
00162 tcsetattr(kfd, TCSANOW, &raw);
00163
00164 puts("Reading from keyboard");
00165 puts("---------------------------");
00166 puts("Use 'WASD' to translate");
00167 puts("Use 'QE' to yaw");
00168 puts("Press 'Shift' to run");
00169
00170
00171 arm_->evil_switch = true;
00172
00173 tf::Stamped<tf::Pose> toolPose = arm_->getToolPose();
00174 double grip_open = gripper_->getAmountOpen();
00175
00176 for (;;)
00177 {
00178
00179 if (read(kfd, &c, 1) < 0)
00180 {
00181 perror("read():");
00182 exit(-1);
00183 }
00184
00185 ROS_INFO("read: %X\n", c);
00186
00187 cmd.linear.x = cmd.linear.y = cmd.angular.z = 0;
00188
00189 btVector3 dist(0,0,0);
00190
00191 switch (c)
00192 {
00193
00194 case KEYCODE_W:
00195
00196 dirty = true;
00197 dist += btVector3(0.01,0,0);
00198 break;
00199 case KEYCODE_S:
00200
00201 dist += btVector3(-0.01,0,0);
00202 dirty = true;
00203 break;
00204 case KEYCODE_A:
00205
00206 dist += btVector3(0,0.01,0);
00207 dirty = true;
00208 break;
00209 case KEYCODE_D:
00210
00211 dist += btVector3(0,-0.01,0);
00212 dirty = true;
00213 break;
00214 case KEYCODE_Q:
00215
00216 dist += btVector3(0,0,0.01);
00217 dirty = true;
00218 break;
00219 case KEYCODE_E:
00220
00221 dist += btVector3(0,0,-0.01);
00222 dirty = true;
00223 break;
00224
00225
00226 case KEYCODE_I:
00227 toolPose = arm_->rotateAroundBaseAxis(toolPose,0.1,0,0);
00228 dirty = true;
00229 break;
00230 case KEYCODE_K:
00231 toolPose = arm_->rotateAroundBaseAxis(toolPose,-0.1,0,0);
00232 dirty = true;
00233 break;
00234 case KEYCODE_J:
00235 toolPose = arm_->rotateAroundBaseAxis(toolPose,0,0,0.1);
00236 dirty = true;
00237 break;
00238 case KEYCODE_L:
00239 toolPose = arm_->rotateAroundBaseAxis(toolPose,0,0,-0.1);
00240 dirty = true;
00241 break;
00242 case KEYCODE_N:
00243 toolPose = arm_->rotateAroundBaseAxis(toolPose,0,0.1,0);
00244 dirty = true;
00245 break;
00246 case KEYCODE_M:
00247 toolPose = arm_->rotateAroundBaseAxis(toolPose,0,-0.1,0);
00248 dirty = true;
00249 break;
00250
00251 case KEYCODE_I_CAP:
00252 toolPose = arm_->rotateAroundToolframeAxis(toolPose,0.1,0,0);
00253 dirty = true;
00254 break;
00255 case KEYCODE_K_CAP:
00256 toolPose = arm_->rotateAroundToolframeAxis(toolPose,-0.1,0,0);
00257 dirty = true;
00258 break;
00259 case KEYCODE_J_CAP:
00260 toolPose = arm_->rotateAroundToolframeAxis(toolPose,0,0,0.1);
00261 dirty = true;
00262 break;
00263 case KEYCODE_L_CAP:
00264 toolPose = arm_->rotateAroundToolframeAxis(toolPose,0,0,-0.1);
00265 dirty = true;
00266 break;
00267 case KEYCODE_N_CAP:
00268 toolPose = arm_->rotateAroundToolframeAxis(toolPose,0,0.1,0);
00269 dirty = true;
00270 break;
00271 case KEYCODE_M_CAP:
00272 toolPose = arm_->rotateAroundToolframeAxis(toolPose,0,-0.1,0);
00273 dirty = true;
00274 break;
00275
00276
00277 case KEYCODE_BRACK_OP:
00278 grip_open += 0.0025;
00279 grip_dirty = true;
00280 break;
00281 case KEYCODE_BRACK_CL:
00282 grip_open -= 0.0025;
00283 grip_dirty = true;
00284 break;
00285
00286
00287 case KEYCODE_R:
00288 toolPose = arm_->getToolPose();
00289 break;
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 }
00321
00322 if (dirty)
00323 {
00324
00325 dist *= 5;
00326 toolPose.setOrigin(toolPose.getOrigin() + dist);
00327
00328 arm_->move_toolframe_ik_pose(toolPose);
00329 dirty = false;
00330 }
00331
00332 if (grip_dirty)
00333 {
00334
00335 gripper_->closeHard(grip_open);
00336 for (int m = 0 ; m < 5; ++m)
00337 {
00338 double am_open = gripper_->getAmountOpen();
00339 ROS_INFO("GRIPPER OPENING :%f (getAmountOpen reports %f)", grip_open, am_open);
00340 }
00341 grip_dirty = false;
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351 }
00352 }