Nclient.h
1 /*
2  * Copyright (C) 1991-2000 Nomadic Technologies
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 
20 /*
21  * Nclient.h
22  *
23  * Interface file for direct connections to the robot or for
24  * connections to Nserver.
25  */
26 
27 /*
28  * $Log: Nclient.h,v $
29  * Revision 1.1.1.1 2001/08/23 19:05:14 bananajr
30  * initial commit
31  *
32  */
33 
34 #ifndef _HOST_CLIENT_NCLIENT_H_
35 #define _HOST_CLIENT_NCLIENT_H_
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /* constants */
42 
43 #ifndef FALSE
44 #define FALSE 0
45 #endif
46 #ifndef TRUE
47 #define TRUE 1
48 #endif
49 #ifndef NULL
50 #define NULL 0
51 #endif
52 #define MAX_VERTICES 10
53 #define NUM_STATE 45
54 #define NUM_MASK 44
55 #define NUM_LASER 482
56 #define BUFSIZE 4096
57 #define MAX_USER_BUF 0xFFFF
58 
59 /* Robot models. */
60 #define MODEL_N200 0
61 #define MODEL_N150 1
62 #define MODEL_SCOUT 2
63 #define MODEL_SCOUT2 2
64 
65 /* the number of sonars and infrareds */
66 #define SONARS 16
67 #define INFRAREDS 16
68 
69 /*
70  * The following defines allow you to access the State vector in a
71  * more readable way.
72  */
73 
74 #define STATE_SIM_SPEED 0
75 
76 #define STATE_IR_0 1
77 #define STATE_IR_1 2
78 #define STATE_IR_2 3
79 #define STATE_IR_3 4
80 #define STATE_IR_4 5
81 #define STATE_IR_5 6
82 #define STATE_IR_6 7
83 #define STATE_IR_7 8
84 #define STATE_IR_8 9
85 #define STATE_IR_9 10
86 #define STATE_IR_10 11
87 #define STATE_IR_11 12
88 #define STATE_IR_12 13
89 #define STATE_IR_13 14
90 #define STATE_IR_14 15
91 #define STATE_IR_15 16
92 
93 #define STATE_SONAR_0 17
94 #define STATE_SONAR_1 18
95 #define STATE_SONAR_2 19
96 #define STATE_SONAR_3 20
97 #define STATE_SONAR_4 21
98 #define STATE_SONAR_5 22
99 #define STATE_SONAR_6 23
100 #define STATE_SONAR_7 24
101 #define STATE_SONAR_8 25
102 #define STATE_SONAR_9 26
103 #define STATE_SONAR_10 27
104 #define STATE_SONAR_11 28
105 #define STATE_SONAR_12 29
106 #define STATE_SONAR_13 30
107 #define STATE_SONAR_14 31
108 #define STATE_SONAR_15 32
109 
110 #define STATE_BUMPER 33
111 #define STATE_CONF_X 34
112 #define STATE_CONF_Y 35
113 #define STATE_CONF_STEER 36
114 #define STATE_CONF_TURRET 37
115 #define STATE_VEL_TRANS 38
116 #define STATE_VEL_RIGHT 38 /* for scout */
117 #define STATE_VEL_STEER 39
118 #define STATE_VEL_LEFT 39 /* for scout */
119 #define STATE_VEL_TURRET 40
120 #define STATE_MOTOR_STATUS 41
121 #define STATE_LASER 42
122 #define STATE_COMPASS 43
123 #define STATE_ERROR 44
124 
125 /*
126  * The following defines allow you to access the Smask vector in a
127  * more readable way.
128  */
129 
130 #define SMASK_POS_DATA 0
131 
132 #define SMASK_IR_1 1
133 #define SMASK_IR_2 2
134 #define SMASK_IR_3 3
135 #define SMASK_IR_4 4
136 #define SMASK_IR_5 5
137 #define SMASK_IR_6 6
138 #define SMASK_IR_7 7
139 #define SMASK_IR_8 8
140 #define SMASK_IR_9 9
141 #define SMASK_IR_10 10
142 #define SMASK_IR_11 11
143 #define SMASK_IR_12 12
144 #define SMASK_IR_13 13
145 #define SMASK_IR_14 14
146 #define SMASK_IR_15 15
147 #define SMASK_IR_16 16
148 
149 #define SMASK_SONAR_1 17
150 #define SMASK_SONAR_2 18
151 #define SMASK_SONAR_3 19
152 #define SMASK_SONAR_4 20
153 #define SMASK_SONAR_5 21
154 #define SMASK_SONAR_6 22
155 #define SMASK_SONAR_7 23
156 #define SMASK_SONAR_8 24
157 #define SMASK_SONAR_9 25
158 #define SMASK_SONAR_10 26
159 #define SMASK_SONAR_11 27
160 #define SMASK_SONAR_12 28
161 #define SMASK_SONAR_13 29
162 #define SMASK_SONAR_14 30
163 #define SMASK_SONAR_15 31
164 #define SMASK_SONAR_16 32
165 
166 #define SMASK_BUMPER 33
167 #define SMASK_CONF_X 34
168 #define SMASK_CONF_Y 35
169 #define SMASK_CONF_STEER 36
170 #define SMASK_CONF_TURRET 37
171 #define SMASK_VEL_TRANS 38
172 #define SMASK_VEL_STEER 39
173 #define SMASK_VEL_TURRET 40
174 #define SMASK_RESERVED 41
175 #define SMASK_LASER 42
176 #define SMASK_COMPASS 43
177 
178 /*
179  * These defines are used for specifying the control modes in the
180  * robot motion command 'mv'. If MV_IGNORE is specified for an axis
181  * the current motion command for it will remain active. Specifying
182  * MV_VM or MV_PR will select velocity and position control as in
183  * the vm and pr robot motion commands
184  */
185 
186 #define MV_IGNORE 0
187 #define MV_VM 1 /* velocity mode */
188 #define MV_PR 2 /* position relative mode */
189 #define MV_LP 3 /* limp mode */
190 #define MV_AC 4 /* set acceleration for vm, pr, pa modes*/
191 #define MV_SP 5 /* set velocity for pr, pa modes */
192 #define MV_PA 6 /* position absolute mode */
193 #define MV_TQ 7 /* torque mode */
194 #define MV_MT 8 /* set maximum torque for vm, pr, pa, tq modes */
195 
196 /*
197  * zeroing modes for arm
198  */
199 
200 #define ZR_CHECK 1
201 #define ZR_ORIENT 2
202 #define ZR_NO_N_GRIPPER 4
203 
204 /*
205  * user packet constants for arm
206  */
207 
208 #define ARM_ZR 40
209 #define ARM_WS 41
210 #define ARM_MV 42
211 
212 /*
213  * function prototypes for arm
214  */
215 long arm_mv(long l_mode, long l_v, long g_mode, long g_v);
216 long arm_ws(short lift, short grip, long timeout, long *time_remain);
217 long arm_zr(short mode);
218 
219 /*
220  * For requesting the PosData the following defines should be used.
221  * Each sensor has a bit, if it is set the pos-data is attached
222  * when the sensory data is returned.
223  */
224 
225 #define POS_NONE ( 0 << 0 )
226 #define POS_INFRARED ( 1 << 0 )
227 #define POS_SONAR ( 1 << 1 )
228 #define POS_BUMPER ( 1 << 2 )
229 #define POS_LASER ( 1 << 3 )
230 #define POS_COMPASS ( 1 << 4 )
231 
232 /*
233  * these macros enable the user to determine if the pos-attachment
234  * is requested for a specific sensor. 1 is returned if the
235  * attachment is requested, 0 otherwise
236  *
237  * Note that the function posDataCheck() is called (see below)
238  */
239 
240 #define POS_INFRARED_P ( ( (posDataCheck()) & POS_INFRARED ) ? 1 : 0 )
241 #define POS_SONAR_P ( ( (posDataCheck()) & POS_SONAR ) ? 1 : 0 )
242 #define POS_BUMPER_P ( ( (posDataCheck()) & POS_BUMPER ) ? 1 : 0 )
243 #define POS_LASER_P ( ( (posDataCheck()) & POS_LASER ) ? 1 : 0 )
244 #define POS_COMPASS_P ( ( (posDataCheck()) & POS_COMPASS ) ? 1 : 0 )
245 
246 /*
247  * The user will be able to call a function that fills out a
248  * list of position data for a specific sensor reading.
249  * To access the sensors in that structure the following defines
250  * should be used. They should also be used if data for a single
251  * infrared sensor / sonar is requested.
252  */
253 
254 #define POS_IR_1 0
255 #define POS_IR_2 1
256 #define POS_IR_3 2
257 #define POS_IR_4 3
258 #define POS_IR_5 4
259 #define POS_IR_6 5
260 #define POS_IR_7 6
261 #define POS_IR_8 7
262 #define POS_IR_9 8
263 #define POS_IR_10 9
264 #define POS_IR_11 10
265 #define POS_IR_12 11
266 #define POS_IR_13 12
267 #define POS_IR_14 13
268 #define POS_IR_15 14
269 #define POS_IR_16 15
270 
271 #define POS_SONAR_1 0
272 #define POS_SONAR_2 1
273 #define POS_SONAR_3 2
274 #define POS_SONAR_4 3
275 #define POS_SONAR_5 4
276 #define POS_SONAR_6 5
277 #define POS_SONAR_7 6
278 #define POS_SONAR_8 7
279 #define POS_SONAR_9 8
280 #define POS_SONAR_10 9
281 #define POS_SONAR_11 10
282 #define POS_SONAR_12 11
283 #define POS_SONAR_13 12
284 #define POS_SONAR_14 13
285 #define POS_SONAR_15 14
286 #define POS_SONAR_16 15
287 
288 
289 /* Define the length of the user buffer (Maximal short).
290  * Due to Protocol bytes, the effective length is 65526
291  */
292 #define USER_BUFFER_LENGTH 0xFFFF
293 
294 
295 /* these definitions apply to the Scout and SuperScout */
296 #define ROTATION_CONSTANT 0.118597 /* inches/degree (known to 100 ppm) */
297 
298 #define RIGHT(trans, steer) (trans + (int)((float)steer*ROTATION_CONSTANT))
299 #define LEFT(trans, steer) (trans - (int)((float)steer*ROTATION_CONSTANT))
300 
301 #define scout_vm(trans, steer) vm(RIGHT(trans, steer), LEFT(trans, steer), 0)
302 
303 /********************
304  * *
305  * Type definitions *
306  * *
307  ********************/
308 
309 /*
310  * The following type definitions are used for the PosData.
311  * PosData is an information packet that is attached to
312  * each sensor reading, if requested. Note that the use of
313  * PosData could cause compatibility problems when different
314  * releases of the software are used on the robot and on the
315  * server side.
316  *
317  * The information packet can be used to determine how up-to-date
318  * a sensory reading is. It contains the configuration of the robot.
319  * This is the most updated configuration at the time of the sensor
320  * reading. However, it is possible that the sensory reading
321  * was taken after the integration of the coniguration.
322  * To determine the interval that has passed two timestamps are in-
323  * cluded in this information package: a timestamp for the computation
324  * of the configuration and another timestamp for the actual capturing
325  * of the senor reading.
326  *
327  * The timestamps are in milliseconds of the internal clock of the
328  * board that handles the sensors (Intellisys 100 sensor-board).
329  */
330 
331 /*
332  * TimeData contains the current time of the Intellisys 100
333  * in milliseconds
334  */
335 
336 typedef unsigned long TimeData;
337 
338 /*
339  * ConfigData is where the i486 writes the current configuration
340  * of the robot, so that the Intellisys 100 can attach current
341  * integration values to the sensor readings.
342  * It is also used inside of the Pos data.
343  */
344 
345 typedef struct _ConfigData
346 {
347  /* the configuration of the robot */
348  long configX;
349  long configY;
350  long configSteer;
351  long configTurret;
352 
353  /* the velocities of the robot*/
354  long velTrans;
355  long velSteer;
356  long velTurret;
357 
358  /* time of integration in milliseconds (Intellisys 100 time) */
359  TimeData timeStamp;
360 
361 } ConfigData;
362 
363 
364 /*
365  * PosData contains information that is attached to a sensor
366  * reading in order to determine how recent it is.
367  */
368 
369 typedef struct _PosData
370 {
371  /* the configuration of the robot at the time of the reading */
372  ConfigData config;
373 
374  /* the time of the sensing in milliseconds (Intellisys 100 time) */
375  TimeData timeStamp;
376 
377 } PosData;
378 
379 /* these type definitions are for user defined package processing */
380 
381 typedef union
382 {
383  char bytes[8];
384  double data;
385 } double_union;
386 
387 typedef union
388 {
389  char bytes[4];
390  short words[2];
391  long data;
392 } long_union;
393 
394 typedef union
395 {
396  unsigned char bytes[2];
397  short data;
398 } short_union;
399 
400 typedef union
401 {
402  unsigned char bytes[2];
403  unsigned short data;
404 } ushort_union;
405 
406 typedef union
407 {
408  unsigned char bytes[4];
409  unsigned short words[2];
410  unsigned long data;
411 } ulong_union;
412 
414 {
415  short type;
416  unsigned short size;
417  long mesg[USER_BUFFER_LENGTH];
418 };
419 
421 {
422  short type;
423  unsigned short size;
424  long mesg[USER_BUFFER_LENGTH];
425 };
426 
427 /********************
428  * *
429  * Global Variables *
430  * *
431  ********************/
432 
433 /* The State vector is an array of 45 long integers:
434  *
435  * State[0] - stores actual simulation speed with 10 being realtime
436  * (20 meaning twice as fast as realtime and 5 meaning half the
437  * speed of realtime).
438  * State[1 ... 16] - stores the 16 infrared data.
439  * State[17 ... 32] - stores the 16 sonar data.
440  * State[33] - stores bumper data
441  * State[34 ... 37] - stores robot configuration
442  * State[38 ... 40] - stores robot's current velocities
443  * State[41] - motor status: the lowest bit is set to 1 if the translational
444  * motor is active; the second lowest bit is set to 1 if the
445  * steering motor is active; the third lowest bit is set to 1 if
446  * the turret motor is active.
447  * State[42] - laser mode: the mode of the laser.
448  * State[43] - compass value.
449  * State[44] - error number.
450  */
451 extern long State[NUM_STATE];
452 
453 /* The Smask vector is an array of 44 integers:
454  *
455  * Smask[0] - used for the posData attachment to sensory data
456  * Smask[1 ... 16] - infrared mask
457  * Smask[17 ... 32] - sonar mask
458  * Smask[33] - bumper mask
459  * Smask[34 ... 37] - configuration mask
460  * Smask[38 ... 40] - velocity mask
461  * Smask[41] - irrelevant.
462  * Smask[42] - laser mask
463  * Smask[43] - compass mask
464  */
465 extern int Smask[NUM_MASK];
466 
467 /* Mask is now just a pointer to Smask. This is because Mask is a declared
468  * variable in X11 library. So if you are not using X11, you can uncomment
469  * the following line and keep using Mask as before. However, if you want
470  * to use X11 graphic in your application program, you can simply use Smask
471  * instead.
472  */
473 /* static int *Mask = Smask; */
474 
475 /* The Laser vector is an array of 965 elements. The Laser vector
476  * can contain laser data in one of the three formats: pixel, point, or line.
477  *
478  * In pixel mode (not available in simulation, Laser[0] keeps the number of
479  * pixels in the Laser vector. The can be a maximum of 482 pixels.
480  *
481  * In point mode, Laser[0] keeps the number of points. Each point is
482  * specified y the two numbers: the x and y coordinates of the point in
483  * the robot's local coordinate. There can be a maximum of 482 points
484  * (thus 964 numbers).
485  *
486  * In line mode, Laser[0] keeps the number of lines. Each line segment is
487  * specified by its two end points and each end point is specified by its
488  * x and y coordinates in the robot's local coordinate. There can be a
489  * maximum of 241 points.
490  */
491 extern int Laser[2*NUM_LASER+1];
492 
493 /* If linking the application program with Nclient.o, it will connect
494  * to Nserver. To specify to which machine to connect and which port
495  * to use the following variables can be redefined, otherwise default
496  * values are used:
497  * SERVER_MACHINE_NAME
498  * SERV_TCP_PORT
499  *
500  * If linking the application program with Ndirect.o, it will connect
501  * directly to the robot. To specify to which robot to connect and
502  * which parameters to use for the connection the following variables
503  * can be redefined, otherwise default vaues are used:
504  * ROBOT_MACHINE_NAME
505  * usually don't need to be changed:
506  * CONN_TYPE
507  * SERIAL_PORT
508  * SERIAL_BAUD
509  * ROBOT_TCP_PORT
510  *
511  * If an application program should run with Nclient.o and Ndirect.o
512  * all of the above variables should be initialized.
513  *
514  * The concerend variables are define below.
515  */
516 
517 /* SERVER_MACHINE_NAME is the name of the machine where the server is
518  * running. You should specify the server machine name in your
519  * program if the server is running on a computer different from
520  * where the client is running
521  */
522 extern char SERVER_MACHINE_NAME[80];
523 
524 /* SERV_TCP_PORT is an arbitrary port number the server listens to for
525  * request of connection. It should be the same as that specified in the
526  * world.setup file. You may modify this number and that in the world.setup
527  * file to allow multiple servers running on the same machine.
528  */
529 extern int SERV_TCP_PORT;
530 
531 /* ROBOT_MACHINE_NAME is the name of the machine on the robot
532  */
533 extern char ROBOT_MACHINE_NAME[80];
534 
535 /* CONN_TYPE is the selection between using a serial port or a TCP/IP port.
536  * If set to 1, serial port is used. If set to 2 (the default), TCP/IP port
537  * is used. If set to any other value, connection will fail.
538  */
539 extern int CONN_TYPE;
540 
541 /* SERIAL_PORT is a string containing the filename of the serial port you
542  * choose to communicate to the robot on. The default is "/dev/ttyS0".
543  */
544 extern char SERIAL_PORT[40];
545 
546 /* SERIAL_BAUD is the baud rate to set the serial communication to. It
547  * defaults to 9600.
548  */
549 extern int SERIAL_BAUD;
550 
551 /* ROBOT_TCP_PORT is the port number the robot listens on for request of
552  * connection. It defaults (and should always be set) to 65001 for the
553  * standard binary port.
554  */
555 extern int ROBOT_TCP_PORT;
556 
557 /* LASER_CALIBRATION and LASER_OFFSET are the values that the laser
558  * calibration software returns to you in the file Laser.cal, and that
559  * are normally stored in the file robot.setup under [laser]calibration
560  * and [laser]offset when Nserver is present. Set these values with
561  * the properly calculated values for your laser system if you have one.
562  * This is only needed for linking with Ndirect.o.
563  */
564 
565 extern double LASER_CALIBRATION[8];
566 extern double LASER_OFFSET[2];
567 
568 /*****************************
569  * *
570  * Robot Interface Functions *
571  * *
572  *****************************/
573 
574 /*
575  * create_robot - requests the server to create a robot with
576  * id = robot_id and establishes a connection with
577  * the robot. This function is disabled in this
578  * version of the software.
579  *
580  * parameters:
581  * long robot_id -- id of the robot to be created. The robot
582  * will be referred to by this id. If a process
583  * wants to talk (connect) to a robot, it must
584  * know its id.
585  */
586 int create_robot(long robot_id);
587 
588 /*
589  * connect_robot - requests the server to connect to the robot
590  * with id = robot_id. In order to talk to the server,
591  * the SERVER_MACHINE_NAME and SERV_TCP_PORT must be
592  * set properly. If a robot with robot_id exists,
593  * a connection is established with that robot. If
594  * no robot exists with robot_id, no connection is
595  * established.
596  *
597  * parameters:
598  * long robot_id -- robot's id. In this multiple robot version, in order
599  * to connect to a robot, you must know it's id.
600  * model -- robot type: 0 = Nomad 200, 1 = Nomad 150, 2 = Scout
601  * *dev -- hostname for TCP, device file for serial ("/dev/" prefix
602  * or ":" suffix means serial)
603  * conn -- TCP port for TCP, baud rate for serial
604  */
605 int connect_robot(long robot_id, ...);
606 
607 /*
608  * disconnect_robot - requests the server to close the connect with robot
609  * with id = robot_id.
610  *
611  * parameters:
612  * long robot_id -- robot's id. In order to disconnect a robot, you
613  * must know it's id.
614  */
615 int disconnect_robot(long robot_id);
616 
617 /*
618  * ac - sets accelerations of the robot. Currently it has no effect in
619  * simulation mode.
620  *
621  * parameters:
622  * int t_ac, s_ac, r_ac -- the translation, steering, and turret
623  * accelerations. t_ac is in 1/10 inch/sec^2
624  * s_ac and r_ac are in 1/10 degree/sec^2.
625  */
626 int ac(int t_ac, int s_ac, int r_ac);
627 
628 /*
629  * sp - sets speeds of the robot, this function will not cause the robot to
630  * move. However, the set speed will be used when executing a pr()
631  * or a pa().
632  *
633  * parameters:
634  * int t_sp, s_sp, r_sp -- the translation, steering, and turret
635  * speeds. t_sp is in 1/10 inch/sec and
636  * s_sp and r_sp are in 1/10 degree/sec.
637  */
638 int sp(int t_sp, int s_sp, int r_sp);
639 
640 /*
641  * pr - moves the motors of the robot by a relative distance, using the speeds
642  * set by sp(). The three parameters specify the relative distances for
643  * the three motors: translation, steering, and turret. All the three
644  * motors move concurrently if the speeds are not set to zero and the
645  * distances to be traveled are non-zero. Depending on the timeout
646  * period set (by function conf_tm(timeout)), the motion may
647  * terminate before the robot has moved the specified distances
648  *
649  * parameters:
650  * int t_pr, s_pr, r_pr -- the specified relative distances of the
651  * translation, steering, and turret motors.
652  * t_pr is in 1/10 inch and s_pr and r_pr are
653  * in 1/10 degrees.
654  */
655 int pr(int t_pr, int s_pr, int r_pr);
656 
657 /*
658  * vm - velocity mode, command the robot to move at translational
659  * velocity = tv, steering velocity = sv, and rotational velocity =
660  * rv. The robot will continue to move at these velocities until
661  * either it receives another command or this command has been
662  * timeout (in which case it will stop its motion).
663  *
664  * parameters:
665  * int t_vm, s_vm, r_vm -- the desired translation, steering, and turret
666  * velocities. tv is in 1/10 inch/sec and
667  * sv and rv are in 1/10 degree/sec.
668  */
669 int vm(int t_vm, int s_vm, int r_vm);
670 
671 /*
672  * mv - move, send a generalized motion command to the robot.
673  * For each of the three axis (translation, steering, and
674  * turret) a motion mode (t_mode, s_mode, r_mode) can be
675  * specified (using the values MV_IGNORE, MV_AC, MV_SP,
676  * MV_LP, MV_VM, and MV_PR defined above):
677  *
678  * MV_IGNORE : the argument for this axis is ignored
679  * and the axis's motion will remain
680  * unchanged.
681  * MV_AC : the argument for this axis specifies
682  * an acceleration value that will be used
683  * during motion commands.
684  * MV_SP : the argument for this axis specifies
685  * a speed value that will be used during
686  * position relative (PR) commands.
687  * MV_LP : the arguemnt for this axis is ignored
688  * but the motor is turned off.
689  * MV_VM : the argument for this axis specifies
690  * a velocity and the axis will be moved
691  * with this velocity until a new motion
692  * command is issued (vm,pr,mv) or
693  * recieves a timeout.
694  * MV_PR : the argument for this axis specifies
695  * a position and the axis will be moved
696  * to this position, unless this command
697  * is overwritten by another (vm,pr,mv).
698  *
699  * parameters:
700  * int t_mode - the desired mode for the tranlation axis
701  * int t_mv - the value for that axis, velocity or position,
702  * depending on t_mode
703  * int s_mode - the desired mode for the steering axis
704  * int s_mv - the value for that axis, velocity or position,
705  * depending on t_mode
706  * int r_mode - the desired mode for the turret axis
707  * int r_mv - the value for that axis, velocity or position,
708  * depending on t_mode
709  */
710 int mv(int t_mode, int t_mv, int s_mode, int s_mv, int r_mode, int r_mv);
711 
712 /*
713  * ct - send the sensor mask, Smask, to the robot. You must first change
714  * the global variable Smask to the desired communication mask before
715  * calling this function.
716  */
717 int ct(void);
718 
719 /*
720  * gs - get the current state of the robot according to the mask (of
721  * the communication channel)
722  */
723 int gs(void);
724 
725 /*
726  * st - stops the robot (the robot holds its current position)
727  */
728 int st(void);
729 
730 /*
731  * lp - set motor limp (the robot may not hold its position).
732  */
733 int lp(void);
734 
735 /*
736  * tk - sends the character stream, talk_string, to the voice synthesizer
737  * to make the robot talk.
738  *
739  * parameters:
740  * char *talk_string -- the string to be sent to the synthesizer.
741  */
742 int tk(char *talk_string);
743 
744 /*
745  * dp - define the current position of the robot as (x,y)
746  *
747  * parameters:
748  * int x, y -- the position to set the robot to.
749  */
750 int dp(int x, int y);
751 
752 /*
753  * zr - zeroing the robot, align steering and turret with bumper zero.
754  * The position, steering and turret angles are all set to zero.
755  * This function returns when the zeroing process has completed.
756  */
757 int zr(void);
758 
759 /*
760  * conf_ir - configure infrared sensor system.
761  *
762  * parameters:
763  * int history -- specifies the percentage dependency of the current
764  * returned reading on the previous returned reading.
765  * It should be set between 0 and 10: 0 = no dependency
766  * 10 = full dependency, i.e. the reading will not change
767  * int order[16] -- specifies the firing sequence of the infrared
768  * (#0 .. #15). You can terminate the order list by a
769  * "255". For example, if you want to use only the
770  * front three infrared sensors then set order[0]=0,
771  * order[1]=1, order[2]=15, order[3]=255 (terminator).
772  */
773 int conf_ir(int history, int order[16]);
774 
775 /*
776  * conf_sn - configure sonar sensor system.
777  *
778  * parameters:
779  * int rate -- specifies the firing rate of the sonar in 4 milli-seconds
780  * interval;
781  * int order[16] -- specifies the firing sequence of the sonar (#0 .. #15).
782  * You can terminate the order list by a "255". For
783  * example, if you want to use only the front three
784  * sensors, then set order[0]=0, order[1]=1, order[2]=15,
785  * order[3]=255 (terminator).
786  */
787 int conf_sn(int rate, int order[16]);
788 
789 /*
790  * conf_cp - configure compass system.
791  *
792  * parameters:
793  * int mode -- specifies compass on/off: 0 = off ; 1 = on; 2 = calibrate.
794  * When you call conf_cp (2), the robot will rotate slowly 360
795  * degrees. You must wait till the robot stops rotating before
796  * issuing another command to the robot (takes ~3 minutes).
797  */
798 int conf_cp(int mode);
799 
800 /*
801  * conf_ls - configure laser sensor system:
802  *
803  * parameters:
804  * unsigned int mode -- specifies the on-board processing mode of the laser
805  * sensor data which determines the mode of the data
806  * coming back:
807  * the first bit specifies the on/off;
808  * the second bit specifies point/line mode;
809  * the third to fifth bits specify the
810  * returned data types:
811  * 000 = peak pixel,
812  * 001 = rise pixel,
813  * 010 = fall pixel,
814  * 011 = magnitude,
815  * 100 = distance;
816  * the sixth bit specifies data integrity checking.
817  *
818  * unsigned int threshold -- specifies the inverted acceptable brightness
819  * of the laser line.
820  *
821  * unsigned int width -- specifies the acceptable width in terms
822  * of number of pixels that are brighter than the
823  * set threshold.
824  *
825  * unsigned int num_data -- specifies the number of sampling points.
826  * unsigned int processing -- specifies the number of neighboring
827  * pixels for averaging
828  *
829  * If you don't understand the above, try this one:
830  * conf_ls(51, 20, 20, 20, 4)
831  */
832 int conf_ls(unsigned int mode,
833  unsigned int threshold,
834  unsigned int width,
835  unsigned int num_data,
836  unsigned int processing);
837 
838 /*
839  * conf_tm - sets the timeout period of the robot in seconds. If the
840  * robot has not received a command from the host computer
841  * for more than the timeout period, it will abort its
842  * current motion
843  *
844  * parameters:
845  * unsigned int timeout -- timeout period in seconds. If it is 0, there
846  * will be no timeout on the robot.
847  */
848 int conf_tm(unsigned char timeout);
849 
850 /*
851  * get_ir - get infrared data, independent of mask. However, only
852  * the active infrared sensor readings are valid. It updates
853  * the State vector.
854  */
855 int get_ir(void);
856 
857 /*
858  * get_sn - get sonar data, independent of mask. However, only
859  * the active sonar sensor readings are valid. It updates
860  * the State vector.
861  */
862 int get_sn(void);
863 
864 /*
865  * get_rc - get robot configuration data (x, y, th, tu), independent of
866  * mask. It updates the State vector.
867  */
868 int get_rc(void);
869 
870 /*
871  * get_rv - get robot velocities (translation, steering, and turret) data,
872  * independent of mask. It updates the State vector.
873  */
874 int get_rv(void);
875 
876 /*
877  * get_ra - get robot acceleration (translation, steering, and turret) data,
878  * independent of mask. It updates the State vector.
879  */
880 int get_ra(void);
881 
882 /*
883  * get_cp - get compass data, independent of mask. However, the
884  * data is valid only if the compass is on. It updates the
885  * State vector.
886  */
887 int get_cp(void);
888 
889 /*
890  * get_ls - get laser data point mode, independent of mask. However the
891  * data is valid only of the laser is on. It updates the Laser
892  * vector.
893  */
894 int get_ls(void);
895 
896 /*
897  * get_bp - get bumper data, independent of mask. It updates the State
898  * vector.
899  */
900 int get_bp(void);
901 
902 /*
903  * conf_sg - configure laser sensor system line segment processing mode:
904  *
905  * parameters:
906  * unsigned int threshold -- specifies the threshold value for least-square
907  * fitting. When the error term grows above the
908  * threshold, the line segment will be broken
909  * unsigned int min_points -- specifies the acceptable number of points
910  * to form a line segment.
911  * unsigned int gap -- specifies the acceptable "gap" between two segments
912  * while they can still be treated as one (in 1/10 inch)
913  *
914  * If you don't understand the above, try this one:
915  * conf_sg(50, 4, 30)
916  */
917 int conf_sg(unsigned int threshold,
918  unsigned int min_points,
919  unsigned int gap);
920 
921 /*
922  * get_sg - get laser data line mode, independent of mask. It updates
923  * the laser vector.
924  */
925 int get_sg(void);
926 
927 /*
928  * da - define the current steering angle of the robot to be th
929  * and the current turret angle of the robot to be tu.
930  *
931  * parameters:
932  * int th, tu -- the steering and turret orientations to set the
933  * robot to.
934  */
935 int da(int th, int tu);
936 
937 /*
938  * ws - waits for stop of motors of the robot. This function is intended
939  * to be used in conjunction with pr() and pa() to detect the desired
940  * motion has finished
941  *
942  * parameters:
943  * unsigned char t_ws, s_ws, r_ws -- These three parameters specify
944  * which axis or combination of axis
945  * (translation, steering, and turret)
946  * to wait.
947  * unsigned char timeout -- specifies how long to wait before timing out
948  * (return without stopping the robot).
949  */
950 int ws(unsigned char t_ws, unsigned char s_ws,
951  unsigned char r_ws, unsigned char timeout);
952 
953 /*
954  * get_rpx - get the position of all nearby robots
955  */
956 int get_rpx(long *robot_pos);
957 
958 /*****************************
959  * *
960  * World Interface Functions *
961  * *
962  *****************************/
963 
964 /*
965  * add_obstacle - creates an obstacle and adds it to the obstacle list
966  * of the robot environment.
967  *
968  * No effect in direct mode.
969  *
970  * parameters:
971  * long obs[2*MAX_VERTICES+1] --
972  * The first element of obs specifies the number of
973  * vertices of the polygonal obstacle (must be no greater
974  * than MAX_VERTICES). The subsequent elements of obs
975  * specifies the x and y coordinates of the vertices,
976  * in counter-clockwise direction.
977  */
978 int add_obstacle(long obs[2*MAX_VERTICES+1]);
979 
980 /*
981  * add_Obs - is the same as add_obstacle, for backward compatibility
982  */
983 int add_Obs(long obs[2*MAX_VERTICES+1]);
984 
985 
986 /*
987  * delete_obstacle - deletes an obstacle specified by obs from the robot
988  * environment
989  * parameters:
990  * long obs[2*MAX_VERTICES+1] --
991  * The first element of obs specifies the number of
992  * vertices of the polygonal obstacle (must be no greater
993  * than MAX_VERTICES). The subsequent elements of obs
994  * specifies the x and y coordinates of the vertices,
995  * in counter-clockwise direction.
996  */
997 int delete_obstacle(long obs[2*MAX_VERTICES+1]);
998 
999 /*
1000  * delete_Obs - is the same as delete_obstacle, for backward compatibility
1001  */
1002 int delete_Obs(long obs[2*MAX_VERTICES+1]);
1003 
1004 /*
1005  * move_obstacle - moves the obstacle obs by dx along x direction and
1006  * dy along y direction. obs is modified.
1007  *
1008  * No effect in direct mode.
1009  *
1010  * parameters:
1011  * long obs[2*MAX_VERTICES+1] --
1012  * The first element of obs specifies the number of
1013  * vertices of the polygonal obstacle (must be no greater
1014  * than MAX_VERTICES). The subsequent elements of obs
1015  * specifies the x and y coordinates of the vertices,
1016  * in counter-clockwise direction.
1017  * long dx, dy -- the x and y distances to translate the obstacle
1018  */
1019 int move_obstacle(long obs[2*MAX_VERTICES+1], long dx, long dy);
1020 
1021 /*
1022  * move_Obs - is the same as move_obstacle, for backward compatibility
1023  *
1024  * No effect in direct mode.
1025  *
1026  */
1027 int move_Obs(long obs[2*MAX_VERTICES+1], long dx, long dy);
1028 
1029 /*
1030  * new_world - deletes all obstacles in the current robot world
1031  *
1032  * No effect in direct mode.
1033  *
1034  */
1035 int new_world(void);
1036 
1037 /****************************
1038  * *
1039  * Graphics refresh control *
1040  * *
1041  ****************************/
1042 
1043 /*
1044  * refresh_all - causes all temporary drawing in graphics window, including
1045  * traces, sensors, and client graphics to be erased
1046  */
1047 int refresh_all(void);
1048 
1049 /*
1050  * refresh_all_traces - causes all robot traces in graphics to be erased
1051  */
1052 int refresh_all_traces(void);
1053 
1054 /*
1055  * refresh_actual_trace - causes actual robot trace in graphics to be erased
1056  */
1057 int refresh_actual_trace(void);
1058 
1059 /*
1060  * refresh_encoder_trace - causes encoder robot trace in graphics to be erased
1061  */
1062 int refresh_encoder_trace(void);
1063 
1064 /*
1065  * refresh_all_sensors - causes all sensor drawings in graphics to be erased
1066  */
1067 int refresh_all_sensors(void);
1068 
1069 /*
1070  * refresh_bumper_sensor - causes bumper drawings in graphics to be erased
1071  */
1072 int refresh_bumper_sensor(void);
1073 
1074 /*
1075  * refresh_infrared_sensor - causes infrared drawings in graphics to be erased
1076  */
1077 int refresh_infrared_sensor(void);
1078 
1079 /*
1080  * refresh_sonar_sensor - causes sonar drawings in graphics to be erased
1081  */
1082 int refresh_sonar_sensor(void);
1083 
1084 /*
1085  * refresh_laser_sensor - causes laser drawings in graphics to be erased
1086  */
1087 int refresh_laser_sensor(void);
1088 
1089 /*
1090  * refresh_client_graphics - causes drawings performed by any clients into
1091  * graphics window to be erased
1092  */
1093 int refresh_client_graphics(void);
1094 
1095 /*******************************
1096  * *
1097  * Miscellaneous robot control *
1098  * *
1099  *******************************/
1100 
1101 /*
1102  * init_mask - initialize the sensor mask, Smask.
1103  */
1104 void init_mask(void);
1105 
1106 /*
1107  * init_sensors - initialize the sensor mask, Smask, and send it to the
1108  * robot. It has no effect on the sensors
1109  */
1110 int init_sensors(void);
1111 
1112 /*
1113  * place_robot - places the robot at configuration (x, y, th, tu).
1114  * In simulation mode, it will place both the Encoder-robot
1115  * and the Actual-robot at this configuration. In real robot
1116  * mode, it will call dp(x, y) and da(th, tu).
1117  *
1118  * parameters:
1119  * int x, y -- x-y position of the desired robot configuration
1120  * int th, tu -- the steering and turret orientation of the robot
1121  * desired configuration
1122  */
1123 int place_robot(int x, int y, int th, int tu);
1124 
1125 /*
1126  * special_request - sends a special request (stored in user_send_buffer)
1127  * to the robot and waits for the robot's response (which
1128  * will be stored in user_receive_buffer).
1129  *
1130  * parameters:
1131  * unsigned char *user_send_buffer -- stores data to be sent to the robot
1132  * Should be a pointer to an array of
1133  * 1024 elements
1134  * unsigned char *user_receive_buffer -- stores data received from the robot
1135  * Should be a pointer to an array of
1136  * 1024 elements
1137  */
1138 int special_request(unsigned char *user_send_buffer,
1139  unsigned char *user_receive_buffer);
1140 
1141 /*******************************
1142  * *
1143  * Graphic Interface Functions *
1144  * *
1145  *******************************/
1146 
1147 /*
1148  * draw_robot - this function allows the client to draw a robot at
1149  * configuration x, y, th, tu (using the robot world
1150  * coordinates).
1151  *
1152  * No effect in direct mode.
1153  *
1154  * parameters:
1155  * long x, y -- the x-y position of the robot.
1156  * int th, tu -- the steering and turret orientation of the robot
1157  * int mode - the drawing mode. If mode = 1, the robot is drawn in
1158  * BlackPixel using GXxor (using GXxor you can erase the trace
1159  * of robotby drawing over it). If mode = 2, the robot is
1160  * drawn in BlackPixel using GXxor and in addition, a small arrow
1161  * is drawn at the center of the robot using GXcopy (using this
1162  * mode you can leave a trace of small arrow). If mode = 3,
1163  * the robot is drawn in BlackPixel using GXcopy. When mode > 3,
1164  * the robot is drawn in color (GXxor) using color(mode-3), see
1165  * Color table below.
1166  */
1167 int draw_robot(long x, long y, int th, int tu, int mode);
1168 
1169 
1170 /*
1171  * draw_line - this function allows the client to draw a line from
1172  * (x_1, y_1) to (x_2, y_2) (using the robot world coordinates).
1173  *
1174  * No effect in direct mode.
1175  *
1176  * parameters:
1177  * long x_1, y_1, x_2, y_2 -- the two end-points of the line
1178  * int mode -- the mode of drawing: when mode is 1, the drawing is
1179  * done in BlackPixel using GXcopy; when mode is 2, the drawing
1180  * is done in BlackPixel using GXxor, when mode > 2, the drawing
1181  * is done in color (GXxor) using color(mode-2), see Color table
1182  * below.
1183  */
1184 int draw_line(long x_1, long y_1, long x_2, long y_2, int mode);
1185 
1186 
1187 /*
1188  * draw_arc - this function allows the client to draw arc which is part
1189  * of an ellipse (using the robot world coordinates).
1190  *
1191  * No effect in direct mode.
1192  *
1193  * parameters:
1194  * long x_0, y_0, w, h -- (x_0, y_0) specifies the upper left corner of the
1195  * rectangle bounding the ellipse while w and h
1196  * specifies the width and height of the bounding
1197  * rectangle, respectively.
1198  * int th1, th2 -- th1 and th2 specifies the angular range of the arc.
1199  * int mode -- the mode of drawing: when mode is 1, the drawing is
1200  * done in BlackPixel using GXcopy; when mode is 2, the drawing
1201  * is done in BlackPixel using GXxor, when mode > 2, the drawing
1202  * is done in color (GXxor) using color(mode-2), see Color table
1203  * below.
1204  */
1205 int draw_arc(long x_0, long y_0, long w, long h, int th1, int th2, int mode);
1206 
1207 /*
1208  * Color table:
1209  * color1 = Blue
1210  * color2 = NavyBlue
1211  * color3 = RoyalBlue
1212  * color4 = SteelBlue
1213  * color5 = CadetBlue
1214  * color6 = Green
1215  * color7 = SeaGreen
1216  * color8 = ForestGreen
1217  * color9 = DarkGreen
1218  * color10 = LimeGreen
1219  * color11 = Yellow
1220  * color12 = Orange
1221  * color13 = LightCoral
1222  * color14 = DeepPink
1223  * color15 = OrangeRed
1224  * color16 = Red
1225  * color17 = IndianRed
1226  * color18 = VioletRed
1227  * color19 = DeepPink
1228  * color20 = Maroon
1229  */
1230 
1231 /*************************************
1232  * *
1233  * Miscellaneous Interface Functions *
1234  * *
1235  *************************************/
1236 
1237 /*
1238  * server_is_running - this function queries the server to see
1239  * if it is up and running. If so, this function
1240  * returns a TRUE, otherwise it returns FALSE.
1241  * This function is replaced by connect_robot, but
1242  * is defined here for backward compatibility
1243  *
1244  * No effect in direct mode.
1245  *
1246  */
1247 int server_is_running(void);
1248 
1249 /*
1250  * quit_server - this function allows the client to quit the server
1251  * assuming this feature is enabled in the setup file
1252  * of the server
1253  *
1254  * No effect in direct mode.
1255  *
1256  */
1257 int quit_server(void);
1258 
1259 /*
1260  * real_robot - this function allows the client to switch to
1261  * real robot mode in the server
1262  *
1263  * No effect in direct mode.
1264  *
1265  */
1266 int real_robot(void);
1267 
1268 /*
1269  * simulated_robot - this function allows the client to switch to
1270  * simulated robot mode in the server
1271  *
1272  * No effect in direct mode.
1273  *
1274  */
1275 int simulated_robot(void);
1276 
1277 /*
1278  * predict_sensors - this function predicts the sensor reading of
1279  * the robot assuming it is at position (x, y)
1280  * and orientation th and tu using the map of the
1281  * simulated robot environment. The predicted sensor
1282  * data values are stored in "state" and "laser".
1283  *
1284  * No effect in direct mode.
1285  *
1286  * parameters:
1287  * int x, y, th, tu -- the configuration of the robot
1288  * long *state -- where to put the predicted state data
1289  * int *laser -- where to put the predicted laser data
1290  */
1291 int predict_sensors(int x, int y, int th, int tu, long *state, int *laser);
1292 
1293 /*
1294  * motion_check - this function computes the intersection of a path
1295  * specified by the parameters: type, a1, ..., a7 with
1296  * the obstacles in the robot's environment. If there is
1297  * collision, the function returns 1 and the x-y configuration
1298  * of the robot is stored in collide[0] and collide[1] while
1299  * collide[2] stores the inward normal of the obstacle edge
1300  * that the robot collides with (this information can be
1301  * used to calculate which bumper is hit.). If there is no
1302  * collision, the function returns 0.
1303  *
1304  * No effect in direct mode.
1305  *
1306  * parameters:
1307  * long type - 0 if the path is a line segment
1308  * 1 if the path is an arc of circle
1309  * double a1 a2 - x-y coordinates of the first point of the path (the path
1310  * is directional).
1311  * depending on the value of type, a3 - a7 have different meanings.
1312  * if (type == 0), line segment mode
1313  * double a3 a4 are the x-y coordinates of the second point of the path
1314  * a5, a6, a7 have no meaning
1315  * if (type == 1), arc of circle mode
1316  * double a3 is the angle (in radiance) of the vector connecting the
1317  * center of the circle to the first end-point of the arc
1318  * double a4 is the angle of the vector connecting the center
1319  * of the circle to the second end-point of the arc
1320  * double a5 is the radius of the circle
1321  * double a6 a7 are the x-y coordinate of the center of the circle
1322  */
1323 int motion_check(long type, double a1, double a2, double a3, double a4,
1324  double a5, double a6, double a7, double collide[3]);
1325 
1326 /*
1327  * get_robot_conf - interactively getting the robot's conf, by clicking
1328  * the mouse in the server's Robot window
1329  *
1330  * No effect in direct mode.
1331  *
1332  * parameters:
1333  * long *conf -- should be an array of 4 long integers. The configuration
1334  * of the robot is returned in this array.
1335  */
1336 int get_robot_conf(long *conf);
1337 
1338 /*******************************************
1339  * *
1340  * The following are helper functions for *
1341  * developing user defined host <-> robot *
1342  * communication *
1343  * *
1344  *******************************************/
1345 
1346 /*
1347  * init_receive_buffer - sets the index to 4 which is the point
1348  * at which data should begin to be extracted
1349  *
1350  * parameters:
1351  * unsigned short *index -- is the buffer index
1352  */
1353 int init_receive_buffer(unsigned short *index);
1354 
1355 /*
1356  * extract_receive_buffer_header - extracts the header information:
1357  * length, serial_number, and packettype from the beginning of the
1358  * receive buffer.
1359  *
1360  * parameters:
1361  * short *length -- is the returns the number of chars in the buffer
1362  *
1363  * unsigned char *serial_number -- returns the serial number to be
1364  * assigned to the packet
1365  * unsigned char *packet_type -- returns the type number to be
1366  * assigned to the packet
1367  * unsigned char *buffer -- is the receive buffer
1368  */
1369 int extract_receive_buffer_header(unsigned short *length,
1370  unsigned char *serial_number,
1371  unsigned char *packet_type,
1372  unsigned char *buffer);
1373 
1374 /*
1375  * init_send_buffer - sets the index to 4 which is the point
1376  * at which data should be inserted
1377  *
1378  * parameters:
1379  * unsigned short *index -- is the buffer index
1380  */
1381 int init_send_buffer(unsigned short *index);
1382 
1383 /*
1384  * stuff_send_buffer_header - loads the header information,
1385  * length,serial_number, and packettype into the beginning of the
1386  * buffer. It should be called after the data has been stuffed,
1387  * i.e. index represents the length of the packet.
1388  *
1389  * parameters:
1390  * int index -- is the buffer index which holds the number of chars
1391  * in the buffer
1392  * unsigned char serial_number -- holds the serial number to be
1393  * assigned to the packet
1394  * unsigned char packet_type -- holds the type number to be
1395  * assigned to the packet
1396  *
1397  * unsigned char *buffer -- is the send buffer
1398  */
1399 int stuff_send_buffer_header(unsigned short index, unsigned char serial_number,
1400  unsigned char packet_type, unsigned char *buffer);
1401 
1402 /*
1403  * stuffchar - stuffs a 1 byte char into the send buffer
1404  *
1405  * parameters:
1406  * signed char data -- is the char to be stuffed
1407  * unsigned char *buffer -- is the send buffer
1408  * unsigned short *index -- is the buffer index which will be incremented
1409  * to reflect the bytes stuffed into the buffer
1410  */
1411 int stuffchar(signed char data, unsigned char *buffer, unsigned short *index);
1412 
1413 /*
1414  * stuff2byteint - stuffs a short int(2 bytes) into the send buffer
1415  *
1416  * parameters:
1417  * signed int data -- is the value which will be split apart and stuffed
1418  * bytewise into the send buffer
1419  * unsigned char *buffer -- is the send buffer
1420  * unsigned short *index -- is the buffer index which will be incremented
1421  * to reflect the bytes stuffed into the buffer
1422  */
1423 int stuff2byteint(signed short data,
1424  unsigned char *buffer, unsigned short *index);
1425 
1426 /*
1427  * stuff4byteint - stuffs a long int(4 bytes) into the send buffer
1428  *
1429  * parameters:
1430  * signed long data -- is the value which will be split apart and stuffed
1431  * bytewise into the send buffer
1432  * unsigned char *buffer -- is the send buffer
1433  * unsigned short *index -- is the buffer index which will be incremented
1434  * to reflect the bytes stuffed into the buffer
1435  */
1436 int stuff4byteint(signed long data,
1437  unsigned char *buffer, unsigned short *index);
1438 
1439 /*
1440  * stuffuchar - stuffs an unsigned char into the send buffer
1441  *
1442  * parameters:
1443  * unsigned char data -- is the char to be stuffed
1444  * unsigned char *buffer -- is the send buffer
1445  * unsigned short *index -- is the buffer index which will be incremented
1446  * to reflect the bytes stuffed into the buffer
1447  */
1448 int stuffuchar(unsigned char data,
1449  unsigned char *buffer, unsigned short *index);
1450 
1451 /*
1452  * stuff2byteuint - stuffs an unsigned short int(2 bytes) into the send buffer
1453  *
1454  * parameters:
1455  * unsigned short data -- is the value which will be split apart and
1456  * stuffed bytewise into the send buffer
1457  * unsigned char *buffer -- is the send buffer
1458  * unsigned short *index -- is the buffer index which will be incremented
1459  * to reflect the bytes stuffed into the buffer
1460  */
1461 int stuff2byteuint(unsigned short data, unsigned char *buffer, unsigned short *index);
1462 
1463 /*
1464  * stuff4byteuint - stuffs an unsigned long int(4 bytes) into the send buffer
1465  *
1466  * parameters:
1467  * unsigned long data -- is the value which will be split apart and stuffed
1468  * bytewise into the send buffer
1469  * unsigned char *buffer -- is the send buffer
1470  * unsigned short *index -- is the buffer index which will be incremented
1471  * to reflect the bytes stuffed into the buffer
1472  */
1473 int stuff4byteuint(unsigned long data, unsigned char *buffer, unsigned short *index);
1474 
1475 /*
1476  * stuffdouble - stuffs a double(8 bytes) into the send buffer
1477  *
1478  * parameters:
1479  * double data -- is the value which will be split apart and stuffed
1480  * bytewise into the send buffer
1481  * unsigned char *buffer -- is the send buffer
1482  * unsigned short *index -- is the buffer index which will be incremented
1483  * to reflect the bytes stuffed into the buffer
1484  */
1485 int stuffdouble(double data, unsigned char *buffer, unsigned short *index);
1486 
1487 /*
1488  * extractchar - extracts a char from the receive buffer
1489  *
1490  * parameters:
1491  * unsigned char *buffer -- is the receive buffer which holds the data
1492  * unsigned short *index -- is the receive buffer index which will be
1493  * incremented to reflect the position of the
1494  * next piece of data to be extracted
1495  */
1496 signed char extractchar(unsigned char *buffer, unsigned short *index);
1497 
1498 /*
1499  * extract2byteint - extracts a short int(2 bytes) from the receive buffer
1500  *
1501  * parameters:
1502  * unsigned char *buffer -- is the receive buffer which holds the data
1503  * unsigned short *index -- is the receive buffer index which will be
1504  * incremented to reflect the position of the
1505  * next piece of data to be extracted
1506  */
1507 signed short extract2byteint(unsigned char *buffer, unsigned short *index);
1508 
1509 /*
1510  * extract4byteint - extracts a long int(4 bytes) from the receive buffer
1511  *
1512  * parameters:
1513  * unsigned char *buffer -- is the receive buffer which holds the data
1514  * unsigned short *index -- is the receive buffer index which will be
1515  * incremented to reflect the position of the
1516  * next piece of data to be extracted
1517  */
1518 signed long extract4byteint(unsigned char *buffer, unsigned short *index);
1519 
1520 /*
1521  * extractuchar - extracts an unsigned char from the receive buffer
1522  *
1523  * parameters:
1524  * unsigned char *buffer -- is the receive buffer which holds the data
1525  * unsigned short *index -- is the receive buffer index which will be
1526  * incremented to reflect the position of the
1527  * next piece of data to be extracted
1528  */
1529 unsigned char extractuchar(unsigned char *buffer, unsigned short *index);
1530 
1531 /*
1532  * extract2byteuint - extracts an unsigned short int(2 bytes) from the
1533  * receive buffer
1534  *
1535  * parameters:
1536  * unsigned char *buffer -- is the receive buffer which holds the data
1537  * unsigned short *index -- is the receive buffer index which will be
1538  * incremented to reflect the position of the
1539  * next piece of data to be extracted
1540  */
1541 unsigned short extract2byteuint(unsigned char *buffer, unsigned short *index);
1542 
1543 /*
1544  * extract4byteuint - extracts an unsigned long int(4 bytes) from the
1545  * receive buffer
1546  *
1547  * parameters:
1548  * unsigned char *buffer -- is the receive buffer which holds the data
1549  * unsigned short *index -- is the receive buffer index which will be
1550  * incremented to reflect the position of the
1551  * next piece of data to be extracted
1552  */
1553 unsigned long extract4byteuint(unsigned char *buffer, unsigned short *index);
1554 
1555 /*
1556  * extractdouble - extracts a double(8 bytes) from the receive buffer
1557  *
1558  * parameters:
1559  * unsigned char *buffer -- is the receive buffer which holds the data
1560  * unsigned short *index -- is the receive buffer index which will be
1561  * incremented to reflect the position of the
1562  * next piece of data to be extracted
1563  */
1564 double extractdouble(unsigned char *buffer, unsigned short *index);
1565 
1566 /************************************************
1567  * *
1568  * Global variable access functions for Allegro *
1569  * Common Lisp interface *
1570  * *
1571  ************************************************/
1572 
1573 int get_state(long state[NUM_STATE]);
1574 
1575 int get_laser(int laser[2*NUM_LASER+1]);
1576 
1577 int get_mask(int mask[NUM_MASK]);
1578 
1579 int set_mask(int mask[NUM_MASK]);
1580 
1581 int set_server_machine_name(char *sname);
1582 
1583 int set_serv_tcp_port(int port);
1584 
1585 
1586 /*************************************************
1587  * *
1588  * Functions for the attachment of position *
1589  * data to sensory readings. *
1590  * *
1591  *************************************************/
1592 
1593 /***************
1594  * FUNCTION: posDataRequest
1595  * PURPOSE: request position information for sensors
1596  * ARGUMENTS: int posRequest :
1597  * The argument of this function specifies the sensors
1598  * for which the position information (PosData) should
1599  * be attached to the sensory reading.
1600  * Its value is obtained by ORing the desired defines.
1601  * EXAMPLE: To attach PosData to sonars and laser:
1602  * posDataRequest ( POS_SONAR | POS_LASER );
1603  * ALGORITHM: currently sets the global variable Smask[0] and
1604  * then calls ct() to transmit the change to the server
1605  * RETURN: TRUE if the argument was correct, else FALSE
1606  * SIDE EFFECT: Smask[0]
1607  * CALLS:
1608  * CALLED BY:
1609  ***************/
1610 int posDataRequest ( int posRequest );
1611 
1612 
1613 /***************
1614  * FUNCTION: posDataCheck
1615  * PURPOSE: return the sensors for which the PosData attachment
1616  * is currently requested.
1617  * ARGUMENTS: None
1618  * ALGORITHM: returns the usedSmask that is not globally accessible
1619  * (is set by ct() to be the value of Smask[0])
1620  * RETURN: int, see posDataRequest
1621  * the macros POS_*_P can be used to examine the value
1622  * SIDE EFFECT:
1623  * CALLS:
1624  * CALLED BY:
1625  ***************/
1626 int posDataCheck ( void );
1627 
1628 
1629 /***************
1630  * FUNCTION: posInfraredRingGet
1631  * PURPOSE: copy the PosData for all infrareds to accessible memory
1632  * ARGUMENTS: PosData posData [INFRAREDS] :
1633  * an array of PosData structures that is filled with
1634  * PosData. The position information for each infrared
1635  * containts the configuration of the robot at the time
1636  * of the sensory reading and a timestamp for the
1637  * configuration and the senosry reading .
1638  * ALGORITHM: copies blocks of memory
1639  * RETURN: int, return always TRUE
1640  * SIDE EFFECT:
1641  * CALLS:
1642  * CALLED BY:
1643  ***************/
1644 int posInfraredRingGet ( PosData posData[INFRAREDS] );
1645 
1646 
1647 /***************
1648  * FUNCTION: posInfraredGet
1649  * PURPOSE: copy the PosData for a specific infrared to accessible
1650  * memory
1651  * ARGUMENTS: PosData *posData : the memory location that the information
1652  * will be copied to
1653  * int infraredNumber : the number of the infrared
1654  * ALGORITHM: copies block of memory
1655  * RETURN: int, always returns TRUE
1656  * SIDE EFFECT:
1657  * CALLS:
1658  * CALLED BY:
1659  ***************/
1660 int posInfraredGet ( PosData *posData , int infraredNumber );
1661 
1662 
1663 /***************
1664  * FUNCTION: posSonarRingGet
1665  * PURPOSE: copy the PosData for all sonars to accessible memory
1666  * ARGUMENTS: PosData posData [SONARS] :
1667  * an array of PosData structures that is filled with
1668  * PosData. The position information for each sonar
1669  * containts the configuration of the robot at the time
1670  * of the sensory reading and a timestamp for the
1671  * configuration and the senosry reading .
1672  * ALGORITHM: copies blocks of memory
1673  * RETURN: int, return always TRUE
1674  * SIDE EFFECT:
1675  * CALLS:
1676  * CALLED BY:
1677  ***************/
1678 int posSonarRingGet ( PosData posData[SONARS] );
1679 
1680 
1681 /***************
1682  * FUNCTION: posSonarGet
1683  * PURPOSE: copy the PosData for a specific sonar to accessible memory
1684  * ARGUMENTS: PosData *posData : the memory location that the information
1685  * will be copied to
1686  * int sonarNumber : the number of the sonar
1687  * ALGORITHM: copies block of memory
1688  * RETURN: int, always returns TRUE
1689  * SIDE EFFECT:
1690  * CALLS:
1691  * CALLED BY:
1692  ***************/
1693 int posSonarGet ( PosData *posData , int sonarNumber );
1694 
1695 
1696 /***************
1697  * FUNCTION: posBumperGet
1698  * PURPOSE: copy PosData for the bumper to accessible memory
1699  * ARGUMENTS: PosData *posData : where the data is copied to
1700  * ALGORITHM: copies a block of memory
1701  * RETURN: int, always returns TRUE
1702  * SIDE EFFECT:
1703  * CALLS:
1704  * CALLED BY:
1705  * NOTE: The bumper differs from other sensors in that the
1706  * posData is only updated after one of the bumper sensors
1707  * change its value from zero to one. This means that the
1708  * posData for the bumper always contains the position and
1709  * timeStamps of the latest hit, or undefined information
1710  * if the bumper was not hit yet.
1711  ***************/
1712 int posBumperGet ( PosData *posData );
1713 
1714 
1715 /***************
1716  * FUNCTION: posLaserGet
1717  * PURPOSE: copy PosData for the laser to accessible memory
1718  * ARGUMENTS: PosData *posData : where the data is copied to
1719  * ALGORITHM: copies a block of memory
1720  * RETURN: int, always returns TRUE
1721  * SIDE EFFECT:
1722  * CALLS:
1723  * CALLED BY:
1724  * NOTE: The laser is updated at a frequency of 30Hz.
1725  ***************/
1726 int posLaserGet ( PosData *posData );
1727 
1728 
1729 /***************
1730  * FUNCTION: posCompassGet
1731  * PURPOSE: copy PosData for the compass to accessible memory
1732  * ARGUMENTS: PosData *posData : where the data is copied to
1733  * ALGORITHM: copies a block of memory
1734  * RETURN: int, always returns TRUE
1735  * SIDE EFFECT:
1736  * CALLS:
1737  * CALLED BY:
1738  * NOTE: The compass is updated ad a frequency of 10Hz.
1739  ***************/
1740 int posCompassGet ( PosData *posData );
1741 
1742 
1743 /***************
1744  * FUNCTION: posTimeGet
1745  * PURPOSE: get the PosData time (Intellisys 100) in milliseconds
1746  * ARGUMENTS: None
1747  * ALGORITHM: ---
1748  * RETURN: int
1749  * SIDE EFFECT:
1750  * CALLS:
1751  * CALLED BY:
1752  * NOTE: The resolution of this timer is 16.4 milliseconds;
1753  * the timer starts out at zero when the system is
1754  * turned on and will flow over after 49 days.
1755  ***************/
1756 int posTimeGet ( void );
1757 
1758 
1759 /*************************************************
1760  * *
1761  * Functions to determine the charge level *
1762  * of the batteries for the cpu and the motors. *
1763  * *
1764  *************************************************/
1765 
1766 /***************
1767  * FUNCTION: voltCpuGet
1768  * PURPOSE: get the voltage of the power supply for the CPU
1769  * ARGUMENTS: None
1770  * ALGORITHM: ---
1771  * RETURN: float (the voltage in volt)
1772  * SIDE EFFECT:
1773  * CALLS:
1774  * CALLED BY:
1775  * NOTE: This should never drop below 10.8 volts.
1776  ***************/
1777 float voltCpuGet ( void );
1778 
1779 
1780 /***************
1781  * FUNCTION: voltMotorGet
1782  * PURPOSE: get the voltage of the power supply for the motors
1783  * ARGUMENTS: None
1784  * ALGORITHM: ---
1785  * RETURN: float (the voltage in volt)
1786  * SIDE EFFECT:
1787  * CALLS:
1788  * CALLED BY:
1789  * NOTE: This should never drop below 10.8 volts.
1790  * Returns average of the two motor batteries.
1791  ***************/
1792 float voltMotorGet ( void );
1793 
1794 #ifdef __cplusplus
1795 }
1796 #endif
1797 
1798 #endif /* _HOST_CLIENT_NCLIENT_H_ */
Definition: Nclient.h:406
Definition: Nclient.h:400
Definition: Nclient.h:420
Definition: Nclient.h:387
Definition: Nclient.h:345
Definition: Nclient.h:369
Definition: Nclient.h:413
Definition: Nclient.h:394
Definition: Nclient.h:381

Last updated 12 September 2005 21:38:45