00001 #include <iostream>
00002 #include <stdio.h>
00003 #include <libplayerc++/playerc++.h>
00004 #include <scorpion.h>
00005 #include <args.h>
00006 using namespace PlayerCc;
00007
00008 int
00009 main(int argc, char *argv[])
00010 {
00011
00012 parse_args(argc,argv);
00013
00014 timespec move_sleep = { 5, 0 };
00015 timespec turn_sleep = { 3, 0 };
00016 timespec stop_sleep = { 10, 0 };
00017
00018
00019
00020
00021 try
00022 {
00023 PlayerClient robot(gHostname, gPort);
00024 Position2dProxy pp(&robot, gIndex);
00025 BumperProxy bp(&robot, gIndex);
00026
00027
00028
00029 robot.SetDataMode(PLAYER_DATAMODE_PULL);
00030 robot.SetReplaceRule(true, PLAYER_MSGTYPE_DATA);
00031
00032
00033 double turn_rate = 0.5;
00034 double move_speed = 0.10;
00035
00036
00037
00038 while (true) {
00039
00040 robot.Read();
00041
00042
00043 if (!bp.IsAnyBumped()) {
00044 printf("Nothing ... waiting for bump\n");
00045 pp.SetSpeed(0, 0);
00046 }
00047
00048
00049 if (bp.IsBumped(SCORPION_BUMP_BNE) && bp.IsBumped(SCORPION_BUMP_BNW))
00050 {
00051 printf("Both bumpsensors bumped \n");
00052 pp.SetSpeed(-move_speed, 0);
00053 nanosleep(&move_sleep, NULL);
00054 nanosleep(&move_sleep, NULL);
00055 pp.SetSpeed(0, 0);
00056 }
00057 else if (bp.IsBumped(SCORPION_BUMP_BNW))
00058 {
00059 printf("Left bump!\n");
00060 pp.SetSpeed(-move_speed, 0);
00061 nanosleep(&move_sleep, NULL);
00062 pp.SetSpeed(-move_speed, -turn_rate);
00063 nanosleep(&turn_sleep, NULL);
00064 pp.SetSpeed(0, 0);
00065 }
00066 else if (bp.IsBumped(SCORPION_BUMP_BNE))
00067 {
00068 printf("Right bump!\n");
00069 pp.SetSpeed(-move_speed, 0);
00070 nanosleep(&move_sleep, NULL);
00071 pp.SetSpeed(-move_speed, turn_rate);
00072 nanosleep(&turn_sleep, NULL);
00073 pp.SetSpeed(0, 0);
00074 }
00075 }
00076 }
00077 catch (PlayerCc::PlayerError e)
00078 {
00079 std::cerr << e << std::endl;
00080 return -1;
00081 }
00082 }