27 #include <mraa/i2c.hpp>
33 #define SmartDrive_Motor_ID_1 0x01
34 #define SmartDrive_Motor_ID_2 0x02
35 #define SmartDrive_Motor_ID_BOTH 0x03
37 #define SmartDrive_Dir_Reverse 0x00
38 #define SmartDrive_Dir_Forward 0x01
40 #define SmartDrive_Action_Float 0x00 //stop and let the motor coast.
41 #define SmartDrive_Action_Brake 0x01 //apply brakes, and resist change to tachometer
42 #define SmartDrive_Action_BrakeHold 0x02 //apply brakes, and restore externally forced change to tachometer
45 #define SmartDrive_Completion_Wait_For 0x01
46 #define SmartDrive_Completion_Dont_Wait 0x00
48 #define SmartDrive_DefaultAddress 0x1b
49 #define SmartDrive_VOLTAGE_MULTIPLIER 212.7
53 #define SmartDrive_Speed_Full 90
54 #define SmartDrive_Speed_Medium 60
55 #define SmartDrive_Speed_Slow 25
58 #define SmartDrive_CONTROL_SPEED 0x01
59 #define SmartDrive_CONTROL_RAMP 0x02
60 #define SmartDrive_CONTROL_RELATIVE 0x04
61 #define SmartDrive_CONTROL_TACHO 0x08
62 #define SmartDrive_CONTROL_BRK 0x10
63 #define SmartDrive_CONTROL_ON 0x20
64 #define SmartDrive_CONTROL_TIME 0x40
65 #define SmartDrive_CONTROL_GO 0x80
67 #define SmartDrive_COMMAND 0x41
68 #define SmartDrive_SETPT_M1 0x42
69 #define SmartDrive_SPEED_M1 0x46
70 #define SmartDrive_TIME_M1 0x47
71 #define SmartDrive_CMD_B_M1 0x48
72 #define SmartDrive_CMD_A_M1 0x49
74 #define SmartDrive_SETPT_M2 0x4A
75 #define SmartDrive_SPEED_M2 0x4E
76 #define SmartDrive_TIME_M2 0x4F
77 #define SmartDrive_CMD_B_M2 0x50
78 #define SmartDrive_CMD_A_M2 0x51
81 #define SmartDrive_POSITION_M1 0x52
82 #define SmartDrive_POSITION_M2 0x56
83 #define SmartDrive_STATUS_M1 0x5A
84 #define SmartDrive_STATUS_M2 0x5B
85 #define SmartDrive_TASKS_M1 0x5C
86 #define SmartDrive_TASKS_M2 0x5D
89 #define SmartDrive_P_Kp 0x5E //proportional gain-position
90 #define SmartDrive_P_Ki 0x60 //integral gain-position
91 #define SmartDrive_P_Kd 0x62 //derivative gain-position
92 #define SmartDrive_S_Kp 0x64 //proportional gain-speed
93 #define SmartDrive_S_Ki 0x66 //integral gain-speed
94 #define SmartDrive_S_Kd 0x68 //derivative gain-speed
95 #define SmartDrive_PASSCOUNT 0x6A
96 #define SmartDrive_PASSTOLERANCE 0x6B
98 #define SmartDrive_CHKSUM 0x6C
101 #define SmartDrive_BATT_VOLTAGE 0x6E
102 #define SmartDrive_RESETSTATUS 0x6F
103 #define SmartDrive_CURRENT_M1 0x70
104 #define SmartDrive_CURRENT_M2 0x72
117 #define SmartDrive_MOTOR_CONTROL_ON 0x1
118 #define SmartDrive_MOTOR_IS_RAMPING 0x2
119 #define SmartDrive_MOTOR_IS_POWERED 0x4
120 #define SmartDrive_MOTOR_POS_CTRL_ON 0x8
121 #define SmartDrive_MOTOR_IN_BRAKE_MODE 0x10
122 #define SmartDrive_MOTOR_OVERLOADED 0x20
123 #define SmartDrive_MOTOR_IN_TIME_MODE 0x40
124 #define SmartDrive_MOTOR_IS_STALLED 0x80
159 SmartDrive(
int i2c_bus,
int address = SmartDrive_DefaultAddress);
184 void Run_Unlimited(
int motor_id,
int direction, uint8_t speed);
191 void StopMotor(
int motor_id,
int next_action );
202 void Run_Seconds(
int motor_id,
int direction, uint8_t speed, uint8_t duration,
bool wait_for_completion,
int next_action );
225 void Run_Degrees(
int motor_id,
int direction, uint8_t speed, uint32_t degrees,
bool wait_for_completion,
int next_action);
236 void Run_Rotations(
int motor_id,
int direction, uint8_t speed, uint32_t rotations,
bool wait_for_completion,
int next_action);
247 void Run_Tacho(
int motor_id, uint8_t speed, uint32_t tacho_count,
bool wait_for_completion,
int next_action);
270 void SetPerformanceParameters( uint16_t Kp_tacho, uint16_t Ki_tacho, uint16_t Kd_tacho, uint16_t Kp_speed, uint16_t Ki_speed, uint16_t Kd_speed, uint8_t passcount, uint8_t tolerance);
290 void writeByte(uint8_t addr, uint8_t value);
291 void writeArray(uint8_t* array);
292 uint8_t readByte(uint8_t addr);
293 uint16_t readInteger(uint8_t addr);
294 uint32_t readLongSigned(uint8_t addr);
297 int m_smartdrive_control_address;
298 mraa::I2c m_i2c_smartdrive_control;
void Run_Unlimited(int motor_id, int direction, uint8_t speed)
Definition: smartdrive.cxx:134
void Run_Rotations(int motor_id, int direction, uint8_t speed, uint32_t rotations, bool wait_for_completion, int next_action)
Definition: smartdrive.cxx:259
void Run_Tacho(int motor_id, uint8_t speed, uint32_t tacho_count, bool wait_for_completion, int next_action)
Definition: smartdrive.cxx:300
float GetBattVoltage()
Definition: smartdrive.cxx:107
SmartDrive(int i2c_bus, int address=SmartDrive_DefaultAddress)
Definition: smartdrive.cxx:37
API for the SmartDrive advanced motor controller from OpenElectronis.
Definition: smartdrive.hpp:152
void Run_Degrees(int motor_id, int direction, uint8_t speed, uint32_t degrees, bool wait_for_completion, int next_action)
Definition: smartdrive.cxx:218
void SetPerformanceParameters(uint16_t Kp_tacho, uint16_t Ki_tacho, uint16_t Kd_tacho, uint16_t Kp_speed, uint16_t Ki_speed, uint16_t Kd_speed, uint8_t passcount, uint8_t tolerance)
Definition: smartdrive.cxx:357
void StopMotor(int motor_id, int next_action)
Definition: smartdrive.cxx:159
void Run_Seconds(int motor_id, int direction, uint8_t speed, uint8_t duration, bool wait_for_completion, int next_action)
Definition: smartdrive.cxx:167
uint32_t ReadTachometerPosition(int motor_id)
Definition: smartdrive.cxx:120
void WaitUntilTimeDone(int motor_id)
Definition: smartdrive.cxx:200
void WaitUntilTachoDone(int motor_id)
Definition: smartdrive.cxx:337
bool IsTachoDone(int motor_id)
Definition: smartdrive.cxx:344
void ReadPerformanceParameters()
Definition: smartdrive.cxx:377
bool IsTimeDone(int motor_id)
Definition: smartdrive.cxx:207
uint8_t GetMotorStatus(int motor_id)
Definition: smartdrive.cxx:393
void PrintMotorStatus(int motor_id)
Definition: smartdrive.cxx:406
void command(uint8_t cmd)
Definition: smartdrive.cxx:100