roomba_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 ROOMBA_COMMS_H
00024 #define ROOMBA_COMMS_H
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00030 #include <limits.h>
00031 
00032 /* command opcodes */
00033 #define ROOMBA_OPCODE_START            128
00034 #define ROOMBA_OPCODE_BAUD             129
00035 #define ROOMBA_OPCODE_CONTROL          130
00036 #define ROOMBA_OPCODE_SAFE             131
00037 #define ROOMBA_OPCODE_FULL             132
00038 #define ROOMBA_OPCODE_POWER            133
00039 #define ROOMBA_OPCODE_SPOT             134
00040 #define ROOMBA_OPCODE_CLEAN            135
00041 #define ROOMBA_OPCODE_MAX              136
00042 #define ROOMBA_OPCODE_DRIVE            137
00043 #define ROOMBA_OPCODE_MOTORS           138
00044 #define ROOMBA_OPCODE_LEDS             139
00045 #define ROOMBA_OPCODE_SONG             140
00046 #define ROOMBA_OPCODE_PLAY             141
00047 #define ROOMBA_OPCODE_SENSORS          142
00048 #define ROOMBA_OPCODE_FORCEDOCK        143
00049 
00050 #define ROOMBA_DELAY_MODECHANGE_MS      20
00051 
00052 #define ROOMBA_MODE_OFF                  0
00053 #define ROOMBA_MODE_PASSIVE              1
00054 #define ROOMBA_MODE_SAFE                 2
00055 #define ROOMBA_MODE_FULL                 3
00056 
00057 #define ROOMBA_TVEL_MAX_MM_S           500     
00058 #define ROOMBA_RADIUS_MAX_MM          2000
00059 
00060 #define ROOMBA_SENSOR_PACKET_SIZE       26
00061 
00062 #define ROOMBA_CHARGING_NOT              0
00063 #define ROOMBA_CHARGING_RECOVERY         1
00064 #define ROOMBA_CHARGING_CHARGING         2
00065 #define ROOMBA_CHARGING_TRICKLE          3
00066 #define ROOMBA_CHARGING_WAITING          4
00067 #define ROOMBA_CHARGING_ERROR            5
00068 
00069 #define ROOMBA_AXLE_LENGTH            0.258
00070 
00071 #define ROOMBA_DIAMETER 0.33
00072 
00073 #define ROOMBA_BUMPER_XOFFSET 0.05
00074 
00075 #ifndef MIN
00076   #define MIN(a,b) ((a < b) ? (a) : (b))
00077 #endif
00078 #ifndef MAX
00079   #define MAX(a,b) ((a > b) ? (a) : (b))
00080 #endif
00081 #ifndef NORMALIZE
00082   #define NORMALIZE(z) atan2(sin(z), cos(z))
00083 #endif
00084 
00085 typedef struct
00086 {
00087   /* Serial port to which the robot is connected */
00088   char serial_port[PATH_MAX];
00089   /* File descriptor associated with serial connection (-1 if no valid
00090    * connection) */
00091   int fd;
00092   /* Current operation mode; one of ROOMBA_MODE_* */
00093   unsigned char mode;
00094   /* Integrated odometric position [m m rad] */
00095   double ox, oy, oa;
00096 
00097   /* Various Boolean flags */
00098   int bumper_left, bumper_right;
00099   unsigned char wheeldrop_caster, wheeldrop_left, wheeldrop_right;
00100   unsigned char wall;
00101   unsigned char cliff_left, cliff_frontleft, cliff_frontright, cliff_right;
00102   unsigned char virtual_wall;
00103   unsigned char overcurrent_driveleft, overcurrent_driveright;
00104   unsigned char overcurrent_mainbrush, overcurrent_sidebrush;
00105   unsigned char overcurrent_vacuum;
00106   unsigned char dirtdetector_right, dirtdetector_left;
00107   unsigned char remote_opcode;
00108   unsigned char button_power, button_spot, button_clean, button_max;
00109 
00110   /* One of ROOMBA_CHARGING_* */
00111   unsigned char charging_state;
00112   /* Volts */
00113   double voltage;
00114   /* Amps */
00115   double current;
00116   /* degrees C */
00117   double temperature;
00118   /* Ah */
00119   double charge;
00120   /* Capacity */
00121   double capacity;
00122 } roomba_comm_t;
00123 
00124 roomba_comm_t* roomba_create(const char* serial_port);
00125 void roomba_destroy(roomba_comm_t* r);
00126 int roomba_open(roomba_comm_t* r, unsigned char fullcontrol, int roomba500);
00127 int roomba_init(roomba_comm_t* r, unsigned char fullcontrol);
00128 int roomba_close(roomba_comm_t* r);
00129 int roomba_set_speeds(roomba_comm_t* r, double tv, double rv);
00130 int roomba_parse_sensor_packet(roomba_comm_t* r, 
00131                                unsigned char* buf, size_t buflen);
00132 int roomba_get_sensors(roomba_comm_t* r, int timeout);
00133 void roomba_print(roomba_comm_t* r);
00134 int roomba_clean(roomba_comm_t* r);
00135 int roomba_forcedock(roomba_comm_t* r);
00136 
00137 int roomba_set_song(roomba_comm_t* r, unsigned char songNumber, 
00138                     unsigned char songLength, unsigned char *notes, 
00139                     unsigned char *noteLengths);
00140 int roomba_play_song(roomba_comm_t *r, unsigned char songNumber);
00141 
00142 int roomba_vacuum(roomba_comm_t *r, int state);
00143 int roomba_set_leds(roomba_comm_t *r, uint8_t dirt_detect, uint8_t max, 
00144                     uint8_t clean, uint8_t spot, uint8_t status, 
00145                     uint8_t power_color, uint8_t power_intensity );
00146 
00147 #ifdef __cplusplus
00148 }
00149 #endif
00150 
00151 #endif
00152 

Last updated 12 September 2005 21:38:45