create_comms.h
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2006 -
00004  *     Brian Gerkey
00005  *                      
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 #ifndef CREATE_COMMS_H
00024 #define CREATE_COMMS_H
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 #include <limits.h>
00031 
00032 /* command opcodes */
00033 #define CREATE_OPCODE_START            128
00034 #define CREATE_OPCODE_BAUD             129
00035 #define CREATE_OPCODE_SAFE             131
00036 #define CREATE_OPCODE_FULL             132
00037 #define CREATE_OPCODE_SPOT             134
00038 #define CREATE_OPCODE_COVER            135
00039 #define CREATE_OPCODE_DEMO             136
00040 #define CREATE_OPCODE_DRIVE            137
00041 #define CREATE_OPCODE_MOTORS           138
00042 #define CREATE_OPCODE_LEDS             139
00043 #define CREATE_OPCODE_SONG             140
00044 #define CREATE_OPCODE_PLAY             141
00045 #define CREATE_OPCODE_SENSORS          142
00046 #define CREATE_OPCODE_COVERDOCK        143
00047 #define CREATE_OPCODE_PWM_MOTORS       144
00048 #define CREATE_OPCODE_DRIVE_WHEELS     145
00049 #define CREATE_OPCODE_DIGITAL_OUTPUTS  147
00050 #define CREATE_OPCODE_STREAM           148
00051 #define CREATE_OPCODE_QUERY_LIST       149
00052 #define CREATE_OPCODE_DO_STREAM        150
00053 #define CREATE_OPCODE_SEND_IR_CHAR     151
00054 #define CREATE_OPCODE_SCRIPT           152
00055 #define CREATE_OPCODE_PLAY_SCRIPT      153
00056 #define CREATE_OPCODE_SHOW_SCRIPT      154
00057 #define CREATE_OPCODE_WAIT_TIME        155
00058 #define CREATE_OPCODE_WAIT_DISTANCE    156
00059 #define CREATE_OPCODE_WAIT_ANGLE       157
00060 #define CREATE_OPCODE_WAIT_EVENT       158
00061 
00062 
00063 #define CREATE_DELAY_MODECHANGE_MS      20
00064 
00065 #define CREATE_MODE_OFF                  0
00066 #define CREATE_MODE_PASSIVE              1
00067 #define CREATE_MODE_SAFE                 2
00068 #define CREATE_MODE_FULL                 3
00069 
00070 #define CREATE_TVEL_MAX_MM_S           500     
00071 #define CREATE_RADIUS_MAX_MM          2000
00072 
00073 #define CREATE_SENSOR_PACKET_SIZE       26
00074 
00075 #define CREATE_CHARGING_NOT              0
00076 #define CREATE_CHARGING_RECOVERY         1
00077 #define CREATE_CHARGING_CHARGING         2
00078 #define CREATE_CHARGING_TRICKLE          3
00079 #define CREATE_CHARGING_WAITING          4
00080 #define CREATE_CHARGING_ERROR            5
00081 
00082 #define CREATE_AXLE_LENGTH            0.258
00083 
00084 #define CREATE_DIAMETER 0.33
00085 
00086 #define CREATE_BUMPER_XOFFSET 0.05
00087 
00088 #ifndef MIN
00089   #define MIN(a,b) ((a < b) ? (a) : (b))
00090 #endif
00091 #ifndef MAX
00092   #define MAX(a,b) ((a > b) ? (a) : (b))
00093 #endif
00094 #ifndef NORMALIZE
00095   #define NORMALIZE(z) atan2(sin(z), cos(z))
00096 #endif
00097 
00098 typedef struct
00099 {
00100   /* Serial port to which the robot is connected */
00101   char serial_port[PATH_MAX];
00102   /* File descriptor associated with serial connection (-1 if no valid
00103    * connection) */
00104   int fd;
00105   /* Current operation mode; one of CREATE_MODE_* */
00106   unsigned char mode;
00107   /* Integrated odometric position [m m rad] */
00108   double ox, oy, oa;
00109 
00110   /* Various Boolean flags */
00111   int bumper_left, bumper_right;
00112   unsigned char wheeldrop_caster, wheeldrop_left, wheeldrop_right;
00113   unsigned char wall;
00114   unsigned char cliff_left, cliff_frontleft, cliff_frontright, cliff_right;
00115   unsigned char virtual_wall;
00116   unsigned char overcurrent_driveleft, overcurrent_driveright;
00117   unsigned char overcurrent_mainbrush, overcurrent_sidebrush;
00118   unsigned char overcurrent_vacuum;
00119   unsigned char dirtdetector_right, dirtdetector_left;
00120   unsigned char remote_opcode;
00121   unsigned char button_power, button_spot, button_clean, button_max;
00122 
00123   /* One of CREATE_CHARGING_* */
00124   unsigned char charging_state;
00125   /* Volts */
00126   double voltage;
00127   /* Amps */
00128   double current;
00129   /* degrees C */
00130   double temperature;
00131   /* Ah */
00132   double charge;
00133   /* Capacity */
00134   double capacity;
00135 } create_comm_t;
00136 
00137 create_comm_t* create_create(const char* serial_port);
00138 void create_destroy(create_comm_t* r);
00139 int create_open(create_comm_t* r, unsigned char fullcontrol);
00140 int create_init(create_comm_t* r, unsigned char fullcontrol);
00141 int create_close(create_comm_t* r);
00142 int create_set_speeds(create_comm_t* r, double tv, double rv);
00143 int create_parse_sensor_packet(create_comm_t* r, 
00144                                unsigned char* buf, size_t buflen);
00145 int create_get_sensors(create_comm_t* r, int timeout);
00146 void create_print(create_comm_t* r);
00147 
00148 int create_set_song(create_comm_t* r, unsigned char songNumber, 
00149                     unsigned char songLength, unsigned char *notes, 
00150                     unsigned char *noteLengths);
00151 int create_play_song(create_comm_t *r, unsigned char songNumber);
00152 
00153 int create_vacuum(create_comm_t *r, int state);
00154 int create_set_leds(create_comm_t *r, uint8_t dirt_detect, uint8_t max, 
00155                     uint8_t clean, uint8_t spot, uint8_t status, 
00156                     uint8_t power_color, uint8_t power_intensity );
00157 
00158 int create_run_demo(create_comm_t *r, uint8_t num);
00159 
00160 #ifdef __cplusplus
00161 }
00162 #endif
00163 
00164 #endif
00165 

Last updated 12 September 2005 21:38:45