Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #pragma systemFile
00027
00028 #ifndef __COMMON_H__
00029 #include "common.h"
00030 #endif
00031
00032
00033 #define MSMTRMX_I2C_ADDR 0xB4
00034 #define MSMTRMX_MOTOR_REG 0x42
00035
00036
00037 typedef enum {
00038 MSMTRMX_MODE_FLOAT = 0,
00039 MSMTRMX_MODE_FORWARD = 1,
00040 MSMTRMX_MODE_REVERSE = 2,
00041 MSMTRMX_MODE_BRAKE = 3
00042 } tMSMTRMXSettings;
00043
00044
00045 typedef enum {
00046 MSMTRMX_M1 = 0,
00047 MSMTRMX_M2 = 1,
00048 MSMTRMX_M3 = 2,
00049 MSMTRMX_M4 = 3
00050 } tMSMTRMXMotors;
00051
00052 tByteArray MSMTRMX_I2CMessage;
00053
00054
00055 bool MSMTRMX_Control(tSensors link, tMSMTRMXMotors channel, int power, ubyte address = MSMTRMX_I2C_ADDR);
00056 bool MSMTRMX_Brake(tSensors link, tMSMTRMXMotors channel, unsigned byte brakeForce, ubyte address = MSMTRMX_I2C_ADDR);
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 bool MSMTRMX_Control(tSensors link, tMSMTRMXMotors channel, int power, ubyte address) {
00070 tMSMTRMXSettings dir;
00071
00072 if (power == 0) {
00073 dir = MSMTRMX_MODE_BRAKE;
00074 power = 0;
00075 }
00076 else if (power < 0) {
00077 dir = MSMTRMX_MODE_REVERSE;
00078 power = -power;
00079 }
00080 else if (power > 0) {
00081 dir = MSMTRMX_MODE_FORWARD;
00082 }
00083
00084 memset(MSMTRMX_I2CMessage, 0, sizeof(tByteArray));
00085
00086 MSMTRMX_I2CMessage[0] = 4;
00087 MSMTRMX_I2CMessage[1] = address;
00088 MSMTRMX_I2CMessage[2] = MSMTRMX_MOTOR_REG + channel * 2;
00089 MSMTRMX_I2CMessage[3] = (ubyte) dir;
00090 MSMTRMX_I2CMessage[4] = power;
00091
00092 if (!writeI2C(link, MSMTRMX_I2CMessage)) {
00093 return false;
00094 }
00095
00096 return true;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 bool MSMTRMX_Brake(tSensors link, tMSMTRMXMotors channel, unsigned byte brakeForce, ubyte address) {
00109
00110 memset(MSMTRMX_I2CMessage, 0, sizeof(tByteArray));
00111
00112 MSMTRMX_I2CMessage[0] = 4;
00113 MSMTRMX_I2CMessage[1] = address;
00114 MSMTRMX_I2CMessage[2] = MSMTRMX_MOTOR_REG + channel * 2;
00115 MSMTRMX_I2CMessage[3] = (ubyte) MSMTRMX_MODE_BRAKE;
00116 MSMTRMX_I2CMessage[4] = brakeForce;
00117
00118 if (!writeI2C(link, MSMTRMX_I2CMessage)) {
00119 return false;
00120 }
00121
00122 return true;
00123 }
00124
00125
00126
00127
00128
00129
00130