00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "canio.h"
00022 #include "canio_kvaser.h"
00023 #include "usb_packet.h"
00024 #include <libplayercore/playercore.h>
00025
00026 #ifndef BusType
00027 typedef enum { UNKNOWN, RS232, CANBUS, USB } BusType;
00028 #endif
00029
00030 #define SPEEDTHRESH 0.01
00031
00032
00033 class rmp_frame_t;
00034
00035
00036
00037 class SegwayRMP : public ThreadedDriver
00038 {
00039 public:
00040
00041 SegwayRMP(ConfigFile* cf, int section);
00042 ~SegwayRMP();
00043
00044
00045 virtual int MainSetup();
00046 virtual void MainQuit();
00047 virtual int ProcessMessage(QueuePointer & resp_queue,
00048 player_msghdr * hdr,
00049 void * data);
00051 int CanBusSetup();
00052
00054 int USBSetup();
00055
00056 protected:
00057
00058
00059
00060 player_devaddr_t position_id;
00061 player_position2d_data_t position_data;
00062
00063
00064 player_devaddr_t position3d_id;
00065 player_position3d_data_t position3d_data;
00066
00067
00068 player_devaddr_t power_base_id;
00069 player_power_data_t power_base_data;
00070
00071
00072 player_devaddr_t power_ui_id;
00073 player_power_data_t power_ui_data;
00074
00075 private:
00076
00077 BusType bus_type;
00078 const char* portname;
00079 const char* caniotype;
00080 const char* usb_device;
00081
00082 int timeout_counter;
00083
00084 float max_xspeed, max_yawspeed;
00085
00086 bool firstread;
00087
00088 DualCANIO *canio;
00089 USBIO *usbio;
00090
00091 float curr_xspeed, curr_yawspeed;
00092 float last_xspeed, last_yawspeed;
00093
00094
00095 bool speed_change;
00096
00097
00098
00099 bool motor_allow_enable;
00100
00101
00102 bool motor_enabled;
00103
00104
00105 uint32_t last_raw_yaw, last_raw_left, last_raw_right, last_raw_foreaft;
00106
00107
00108 double odom_x, odom_y, odom_yaw;
00109
00110
00111 int HandlePositionConfig(QueuePointer &resp_queue, uint32_t subtype, void* data, size_t len);
00112
00113
00114 int HandlePosition3DConfig(QueuePointer &resp_queue, uint32_t subtype, void* data, size_t len);
00115
00116
00117 int Read();
00118 int CanBusRead();
00119 int USBRead();
00120
00121
00122
00123 int Diff(uint32_t from, uint32_t to, bool first);
00124
00125
00126 int Write(CanPacket& pkt);
00127
00128
00129 virtual void Main();
00130
00131
00132 void MakeStatusCommand(CanPacket* pkt, uint16_t cmd, uint16_t val);
00133
00134
00135 void MakeVelocityCommand(CanPacket* pkt, int32_t xspeed, int32_t yawspeed);
00136
00137 void MakeShutdownCommand(CanPacket* pkt);
00138
00139 void UpdateData(rmp_frame_t *);
00140 };
00141
00142