?? nclient.h
字號:
typedef struct _PosData{ /* the configuration of the robot at the time of the reading */ ConfigData config; /* the time of the sensing in milliseconds (Intellisys 100 time) */ TimeData timeStamp;} PosData;/* these type definitions are for user defined package processing */typedef union{ char bytes[8]; double data;} double_union;typedef union{ char bytes[4]; short words[2]; long data;} long_union;typedef union{ unsigned char bytes[2]; short data;} short_union;typedef union{ unsigned char bytes[2]; unsigned short data;} ushort_union;typedef union{ unsigned char bytes[4]; unsigned short words[2]; unsigned long data;} ulong_union;struct request_struct{ short type; unsigned short size; long mesg[USER_BUFFER_LENGTH];};struct reply_struct{ short type; unsigned short size; long mesg[USER_BUFFER_LENGTH];};/******************** * * * Global Variables * * * ********************//* The State vector is an array of 45 long integers: * * State[0] - stores actual simulation speed with 10 being realtime * (20 meaning twice as fast as realtime and 5 meaning half the * speed of realtime). * State[1 ... 16] - stores the 16 infrared data. * State[17 ... 32] - stores the 16 sonar data. * State[33] - stores bumper data * State[34 ... 37] - stores robot configuration * State[38 ... 40] - stores robot's current velocities * State[41] - motor status: the lowest bit is set to 1 if the translational * motor is active; the second lowest bit is set to 1 if the * steering motor is active; the third lowest bit is set to 1 if * the turret motor is active. * State[42] - laser mode: the mode of the laser. * State[43] - compass value. * State[44] - error number. */extern long State[NUM_STATE];/* The Smask vector is an array of 44 integers: * * Smask[0] - used for the posData attachment to sensory data * Smask[1 ... 16] - infrared mask * Smask[17 ... 32] - sonar mask * Smask[33] - bumper mask * Smask[34 ... 37] - configuration mask * Smask[38 ... 40] - velocity mask * Smask[41] - irrelevant. * Smask[42] - laser mask * Smask[43] - compass mask */extern int Smask[NUM_MASK];/* Mask is now just a pointer to Smask. This is because Mask is a declared * variable in X11 library. So if you are not using X11, you can uncomment * the following line and keep using Mask as before. However, if you want * to use X11 graphic in your application program, you can simply use Smask * instead. *//* static int *Mask = Smask; *//* The Laser vector is an array of 965 elements. The Laser vector * can contain laser data in one of the three formats: pixel, point, or line. * * In pixel mode (not available in simulation, Laser[0] keeps the number of * pixels in the Laser vector. The can be a maximum of 482 pixels. * * In point mode, Laser[0] keeps the number of points. Each point is * specified y the two numbers: the x and y coordinates of the point in * the robot's local coordinate. There can be a maximum of 482 points * (thus 964 numbers). * * In line mode, Laser[0] keeps the number of lines. Each line segment is * specified by its two end points and each end point is specified by its * x and y coordinates in the robot's local coordinate. There can be a * maximum of 241 points. */extern int Laser[2*NUM_LASER+1];/* If linking the application program with Nclient.o, it will connect * to Nserver. To specify to which machine to connect and which port * to use the following variables can be redefined, otherwise default * values are used: * SERVER_MACHINE_NAME * SERV_TCP_PORT * * If linking the application program with Ndirect.o, it will connect * directly to the robot. To specify to which robot to connect and * which parameters to use for the connection the following variables * can be redefined, otherwise default vaues are used: * ROBOT_MACHINE_NAME * usually don't need to be changed: * CONN_TYPE * SERIAL_PORT * SERIAL_BAUD * ROBOT_TCP_PORT * * If an application program should run with Nclient.o and Ndirect.o * all of the above variables should be initialized. * * The concerend variables are define below. *//* SERVER_MACHINE_NAME is the name of the machine where the server is * running. You should specify the server machine name in your * program if the server is running on a computer different from * where the client is running */extern char SERVER_MACHINE_NAME[80];/* SERV_TCP_PORT is an arbitrary port number the server listens to for * request of connection. It should be the same as that specified in the * world.setup file. You may modify this number and that in the world.setup * file to allow multiple servers running on the same machine. */extern int SERV_TCP_PORT;/* ROBOT_MACHINE_NAME is the name of the machine on the robot */extern char ROBOT_MACHINE_NAME[80];/* CONN_TYPE is the selection between using a serial port or a TCP/IP port. * If set to 1, serial port is used. If set to 2 (the default), TCP/IP port * is used. If set to any other value, connection will fail. */extern int CONN_TYPE;/* SERIAL_PORT is a string containing the filename of the serial port you * choose to communicate to the robot on. The default is "/dev/ttyS0". */extern char SERIAL_PORT[40];/* SERIAL_BAUD is the baud rate to set the serial communication to. It * defaults to 9600. */extern int SERIAL_BAUD;/* ROBOT_TCP_PORT is the port number the robot listens on for request of * connection. It defaults (and should always be set) to 65001 for the * standard binary port. */extern int ROBOT_TCP_PORT;/* LASER_CALIBRATION and LASER_OFFSET are the values that the laser * calibration software returns to you in the file Laser.cal, and that * are normally stored in the file robot.setup under [laser]calibration * and [laser]offset when Nserver is present. Set these values with * the properly calculated values for your laser system if you have one. * This is only needed for linking with Ndirect.o. */extern double LASER_CALIBRATION[8];extern double LASER_OFFSET[2];/***************************** * * * Robot Interface Functions * * * *****************************//* * create_robot - requests the server to create a robot with * id = robot_id and establishes a connection with * the robot. This function is disabled in this * version of the software. * * parameters: * long robot_id -- id of the robot to be created. The robot * will be referred to by this id. If a process * wants to talk (connect) to a robot, it must * know its id. */int create_robot(long robot_id);/* * connect_robot - requests the server to connect to the robot * with id = robot_id. In order to talk to the server, * the SERVER_MACHINE_NAME and SERV_TCP_PORT must be * set properly. If a robot with robot_id exists, * a connection is established with that robot. If * no robot exists with robot_id, no connection is * established. * * parameters: * long robot_id -- robot's id. In this multiple robot version, in order * to connect to a robot, you must know it's id. * model -- robot type: 0 = Nomad 200, 1 = Nomad 150, 2 = Scout * *dev -- hostname for TCP, device file for serial ("/dev/" prefix * or ":" suffix means serial) * conn -- TCP port for TCP, baud rate for serial */int connect_robot(long robot_id, ...);/* * disconnect_robot - requests the server to close the connect with robot * with id = robot_id. * * parameters: * long robot_id -- robot's id. In order to disconnect a robot, you * must know it's id. */int disconnect_robot(long robot_id);/* * ac - sets accelerations of the robot. Currently it has no effect in * simulation mode. * * parameters: * int t_ac, s_ac, r_ac -- the translation, steering, and turret * accelerations. t_ac is in 1/10 inch/sec^2 * s_ac and r_ac are in 1/10 degree/sec^2. */int ac(int t_ac, int s_ac, int r_ac);/* * sp - sets speeds of the robot, this function will not cause the robot to * move. However, the set speed will be used when executing a pr() * or a pa(). * * parameters: * int t_sp, s_sp, r_sp -- the translation, steering, and turret * speeds. t_sp is in 1/10 inch/sec and * s_sp and r_sp are in 1/10 degree/sec. */int sp(int t_sp, int s_sp, int r_sp);/* * pr - moves the motors of the robot by a relative distance, using the speeds * set by sp(). The three parameters specify the relative distances for * the three motors: translation, steering, and turret. All the three * motors move concurrently if the speeds are not set to zero and the * distances to be traveled are non-zero. Depending on the timeout * period set (by function conf_tm(timeout)), the motion may * terminate before the robot has moved the specified distances * * parameters: * int t_pr, s_pr, r_pr -- the specified relative distances of the * translation, steering, and turret motors. * t_pr is in 1/10 inch and s_pr and r_pr are * in 1/10 degrees. */int pr(int t_pr, int s_pr, int r_pr);/* * vm - velocity mode, command the robot to move at translational * velocity = tv, steering velocity = sv, and rotational velocity = * rv. The robot will continue to move at these velocities until * either it receives another command or this command has been * timeout (in which case it will stop its motion). * * parameters: * int t_vm, s_vm, r_vm -- the desired translation, steering, and turret * velocities. tv is in 1/10 inch/sec and * sv and rv are in 1/10 degree/sec. */int vm(int t_vm, int s_vm, int r_vm);/* * mv - move, send a generalized motion command to the robot. * For each of the three axis (translation, steering, and * turret) a motion mode (t_mode, s_mode, r_mode) can be * specified (using the values MV_IGNORE, MV_AC, MV_SP, * MV_LP, MV_VM, and MV_PR defined above): * * MV_IGNORE : the argument for this axis is ignored * and the axis's motion will remain * unchanged. * MV_AC : the argument for this axis specifies * an acceleration value that will be used * during motion commands. * MV_SP : the argument for this axis specifies * a speed value that will be used during * position relative (PR) commands. * MV_LP : the arguemnt for this axis is ignored * but the motor is turned off. * MV_VM : the argument for this axis specifies * a velocity and the axis will be moved * with this velocity until a new motion * command is issued (vm,pr,mv) or * recieves a timeout. * MV_PR : the argument for this axis specifies * a position and the axis will be moved * to this position, unless this command * is overwritten by another (vm,pr,mv). * * parameters: * int t_mode - the desired mode for the tranlation axis * int t_mv - the value for that axis, velocity or position, * depending on t_mode * int s_mode - the desired mode for the steering axis * int s_mv - the value for that axis, velocity or position, * depending on t_mode * int r_mode - the desired mode for the turret axis * int r_mv - the value for that axis, velocity or position, * depending on t_mode */int mv(int t_mode, int t_mv, int s_mode, int s_mv, int r_mode, int r_mv);/* * ct - send the sensor mask, Smask, to the robot. You must first change * the global variable Smask to the desired communication mask before * calling this function. */int ct(void);/* * gs - get the current state of the robot according to the mask (of * the communication channel) */int gs(void);/*
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -