File: userServerTest.cpp

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (152 lines) | stat: -rw-r--r-- 4,136 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "Aria.h"
#include "ArNetworking.h"


int main(int argc, char **argv)
{
  Aria::init();
  //ArLog::init(ArLog::StdOut, ArLog::Verbose);
  // robot
  ArRobot robot;
  /// our server
  ArServerBase server;

  // set up our parser
  ArArgumentParser parser(&argc, argv);
  // set up our simple connector
  ArSimpleConnector simpleConnector(&parser);

  // set up a gyro
  ArAnalogGyro gyro(&robot);

  // load the default arguments 
  parser.loadDefaultArguments();

  // parse the command line... fail and print the help if the parsing fails
  // or if the help was requested
  if (!simpleConnector.parseArgs() || !parser.checkHelpAndWarnUnparsed())
  {    
    simpleConnector.logOptions();
    exit(1);
  }

  if (!server.loadUserInfo("userServerTest.userInfo"))
  {
    printf("Could not load user info, exiting\n");
    exit(1);
  }

  server.logUsers();

  // first open the server up
  if (!server.open(7272))
  {
    printf("Could not open server port\n");
    exit(1);
  }

  // sonar, must be added to the robot
  ArSonarDevice sonarDev;
  // add the sonar to the robot
  robot.addRangeDevice(&sonarDev);

  ArIRs irs;
  robot.addRangeDevice(&irs);

  ArBumpers bumpers;
  robot.addRangeDevice(&bumpers);

  // a laser in case one is used
  ArSick sick(361, 180);
  // add the laser to the robot
  robot.addRangeDevice(&sick);  


  

  // attach stuff to the server
  ArServerInfoRobot serverInfoRobot(&server, &robot);
  ArServerInfoSensor serverInfoSensor(&server, &robot);
  ArServerInfoDrawings drawings(&server);
  drawings.addRobotsRangeDevices(&robot);

  // ways of moving the robot
  ArServerModeStop modeStop(&server, &robot);
  ArServerModeDrive modeDrive(&server, &robot);
  ArServerModeRatioDrive modeRatioDrive(&server, &robot);
  ArServerModeWander modeWander(&server, &robot);
  modeStop.addAsDefaultMode();
  modeStop.activate();

  // set up the simple commands
  ArServerHandlerCommands commands(&server);
  // add the commands for the microcontroller
  ArServerSimpleComUC uCCommands(&commands, &robot);
  // add the commands for logging
  ArServerSimpleComMovementLogging loggingCommands(&commands, &robot);
  // add the commands for the gyro
  ArServerSimpleComGyro gyroCommands(&commands, &robot, &gyro);

  // add the commands to enable and disable safe driving to the simple commands
  modeDrive.addControlCommands(&commands);

  // Forward any video if we have some to forward.. this will forward
  // from SAV or ACTS, you can find both on our website
  // http://robots.activmedia.com, ACTS is for color tracking and is
  // charged for but SAV just does software A/V transmitting and is
  // free to all our customers... just run ACTS or SAV before you
  // start this program and this class here will forward video from it
  // to MobileEyes
  ArHybridForwarderVideo videoForwarder(&server, "localhost", 7070);
  
  // make a camera to use in case we have video
  ArPTZ *camera = NULL;
  ArServerHandlerCamera *handlerCamera = NULL;
  // if we have video then set up a camera 
  if (videoForwarder.isForwardingVideo())
  {
    bool invertedCamera = false;
    camera = new ArVCC4(&robot,	invertedCamera, 
			ArVCC4::COMM_UNKNOWN, true, true);
    camera->init();
    handlerCamera = new ArServerHandlerCamera(&server, &robot, camera);
  }

  server.logCommandGroups();
  server.logCommandGroupsToFile("userServerTest.commandGroups");

  // now let it spin off in its own thread
  server.runAsync();

  // set up the robot for connecting
  if (!simpleConnector.connectRobot(&robot))
  {
    printf("Could not connect to robot... exiting\n");
    Aria::shutdown();
    return 1;
  }

  // set up the laser before handing it to the laser mode
  simpleConnector.setupLaser(&sick);

  robot.enableMotors();
  // start the robot running, true so that if we lose connection the run stops
  robot.runAsync(true);

  sick.runAsync();

  // connect the laser if it was requested
  if (!simpleConnector.connectLaser(&sick))
  {
    printf("Could not connect to laser... exiting\n");
    Aria::shutdown();
    return 1;
  }

  robot.waitForRunExit();
  // now exit
  Aria::shutdown();
  exit(0);  
}