00001 /** 00002 * Defines main functions, serial commands, and data types 00003 * 00004 **/ 00005 00006 #ifndef SCORBOT_H 00007 #define SCORBOT_H 00008 00009 #include "mbed.h" 00010 #include "buffered_serial.h" 00011 #include "motor.h" 00012 00013 /****************************************** 00014 * IO Pin Mappings * 00015 ******************************************/ 00016 #define MS_1_PIN p11 00017 #define MS_2_PIN p12 00018 #define MS_3_PIN p13 00019 #define MS_4_PIN p14 00020 #define MS_5_PIN p15 00021 #define MS_6_PIN p16 00022 #define MS_7_PIN p17 00023 #define PWM_1_PIN p21 00024 #define PWM_2_PIN p22 00025 #define PWM_3_PIN p23 00026 #define PWM_4_PIN p24 00027 #define PWM_5_PIN p25 00028 #define PWM_6_PIN LED1 00029 #define PWM_7_PIN p26 00030 00031 /****************************************** 00032 * Propeller Related Constants * 00033 ******************************************/ 00034 #define PROPELLER_TX p10 00035 #define PROPELLER_RX p9 00036 //the length of the propeller message 00037 #define PROPELLER_DATA_SIZE 30 00038 #define PROPELLER_SENTINEL_CHARACTER 'A' 00039 //propeller messages: 00040 #define PROPELLER_GET_VALUES 10 00041 #define PROPELLER_START_MOTORS 14 00042 #define PROPELLER_STOP_MOTORS 15 00043 #define PROPELLER_RESET_ENCODERS 20 00044 00045 /****************************************** 00046 * I2C to PWM Driver Constants * 00047 ******************************************/ 00048 #define I2C_SDA p28 00049 #define I2C_SCL p27 00050 //the length of the propeller message 00051 #define I2C_TO_PWM_DRIVER_ADDRESS 0x20 00052 00053 00054 00055 class Scorbot 00056 { 00057 public: 00058 Scorbot(); 00059 virtual ~Scorbot(); 00060 00061 uint8_t readMicroswitches(); 00062 uint8_t readMicroswitch(uint8_t motor_index); 00063 long readEncoder(uint8_t motor_index); 00064 float readPWMDuty(uint8_t motor_index); 00065 uint8_t readControllerStatus(); 00066 uint8_t * readControlParameters(uint8_t motor_index, uint8_t & length); 00067 long readTargetPosition(uint8_t motor_index); 00068 long readTargetVelocity(uint8_t motor_index); 00069 void resetEncoders(); 00070 void setDestination(uint8_t motor_index, long position, long duration); 00071 bool setControlParameters(uint8_t motor_index, uint8_t length, uint8_t *params); 00072 void enableMotors(); 00073 void disableMotors(); 00074 00075 00076 //static void setExternalPWMDuty(uint8_t external_pwm_address, uint8_t duty); 00077 //static I2C g_i2c_to_pwm_driver_; 00078 00079 private: 00080 void requestUpdate(); 00081 void updateStep(); 00082 00083 BufferedSerial propeller_; 00084 Motor * motor_[7]; 00085 Ticker request_update_; 00086 uint8_t controller_status_; 00087 }; 00088 00089 #endif /* SCORBOT_H */