EVShield
v1.3
EVShield Library Reference by mindsensors.com
|
This class defines methods for the EVShield Bank(s). More...
#include <EVShield.h>
Public Member Functions | |
EVShieldBank (uint8_t i2c_address=SH_Bank_A) | |
int | evshieldGetBatteryVoltage () |
int | nxshieldGetBatteryVoltage () |
uint8_t | EVShieldIssueCommand (char command) |
bool | motorSetEncoderTarget (SH_Motor which_motor, long target) |
long | motorGetEncoderTarget (SH_Motor which_motor) |
bool | motorSetSpeed (SH_Motor which_motor, int speed) |
int8_t | motorGetSpeed (SH_Motor which_motor) |
bool | motorSetTimeToRun (SH_Motor which_motor, int seconds) |
uint8_t | motorGetTimeToRun (SH_Motor which_motor) |
bool | motorSetCommandRegB (SH_Motor which_motor, uint8_t value) |
uint8_t | motorGetCommandRegB (SH_Motor which_motor) |
bool | motorSetCommandRegA (SH_Motor which_motor, uint8_t value) |
uint8_t | motorGetCommandRegA (SH_Motor which_motor) |
int32_t | motorGetEncoderPosition (SH_Motor which_motor) |
uint8_t | motorGetStatusByte (SH_Motor which_motor) |
uint8_t | motorGetTasksRunningByte (SH_Motor which_motor) |
bool | motorSetEncoderPID (uint16_t Kp, uint16_t Ki, uint16_t Kd) |
bool | motorSetSpeedPID (uint16_t Kp, uint16_t Ki, uint16_t Kd) |
bool | centerLedSetRGB (uint8_t R, uint8_t G, uint8_t B) |
bool | ledSetRGB (uint8_t R, uint8_t G, uint8_t B) |
bool | motorSetPassCount (uint8_t pass_count) |
bool | motorSetTolerance (uint8_t tolerance) |
bool | motorReset () |
bool | motorStartBothInSync () |
bool | motorResetEncoder (SH_Motor which_motor) |
bool | motorSetSpeedTimeAndControl (SH_Motor which_motors, int speed, uint8_t duration, uint8_t control) |
bool | motorSetEncoderSpeedTimeAndControl (SH_Motor which_motors, long encoder, int speed, uint8_t duration, uint8_t control) |
uint8_t | motorIsTimeDone (SH_Motor which_motors) |
uint8_t | motorWaitUntilTimeDone (SH_Motor which_motors) |
uint8_t | motorIsTachoDone (SH_Motor which_motors) |
uint8_t | motorWaitUntilTachoDone (SH_Motor which_motors) |
void | motorRunUnlimited (SH_Motor which_motors, SH_Direction direction, int speed) |
uint8_t | motorRunSeconds (SH_Motor which_motors, SH_Direction direction, int speed, uint8_t duration, SH_Completion_Wait wait_for_completion, SH_Next_Action next_action) |
uint8_t | motorRunTachometer (SH_Motor which_motors, SH_Direction direction, int speed, long tachometer, SH_Move relative, SH_Completion_Wait wait_for_completion, SH_Next_Action next_action) |
uint8_t | motorRunDegrees (SH_Motor which_motors, SH_Direction direction, int speed, long degrees, SH_Completion_Wait wait_for_completion, SH_Next_Action next_action) |
uint8_t | motorRunRotations (SH_Motor which_motors, SH_Direction direction, int speed, long rotations, SH_Completion_Wait wait_for_completion, SH_Next_Action next_action) |
bool | motorStop (SH_Motor which_motors, SH_Next_Action next_action) |
bool | sensorSetType (uint8_t which_sensor, uint8_t sensor_type) |
int | sensorReadRaw (uint8_t which_sensor) |
Public Member Functions inherited from EVShieldI2C | |
EVShieldI2C (uint8_t i2c_address) | |
void | init (void *shield, SH_BankPort bp) |
uint8_t | readByte (uint8_t location) |
uint16_t | readInteger (uint8_t location) |
uint32_t | readLong (uint8_t location) |
uint8_t * | readRegisters (uint8_t start_register, uint8_t bytes, uint8_t *buf) |
char * | readString (uint8_t location, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0) |
bool | writeRegisters (uint8_t start_register, uint8_t bytes_to_write, uint8_t *buffer=0) |
bool | writeByte (uint8_t location, uint8_t data) |
bool | writeInteger (uint8_t location, uint16_t data) |
bool | writeLong (uint8_t location, uint32_t data) |
char * | getFirmwareVersion () |
char * | getVendorID () |
char * | getDeviceID () |
char * | getFeatureSet () |
uint8_t | getErrorCode () |
bool | checkAddress () |
bool | setAddress (uint8_t address) |
Public Member Functions inherited from BaseI2CDevice | |
BaseI2CDevice (uint8_t i2c_address) | |
void | initProtocol () |
uint8_t * | readRegisters (uint8_t start_register, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0, bool clear_buffer=false) |
uint8_t | readByte (uint8_t location) |
int16_t | readInteger (uint8_t location) |
uint32_t | readLong (uint8_t location) |
char * | readString (uint8_t location, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0) |
bool | writeRegisters (uint8_t start_register, uint8_t bytes_to_write, uint8_t *buffer=0) |
bool | writeByte (uint8_t location, uint8_t data) |
bool | writeInteger (uint8_t location, uint16_t data) |
bool | writeLong (uint8_t location, uint32_t data) |
bool | checkAddress () |
bool | setAddress (uint8_t i2c_address) |
uint8_t | getAddress () |
uint8_t | getWriteErrorCode () |
char * | getFirmwareVersion () |
char * | getVendorID () |
char * | getDeviceID () |
char * | getFeatureSet () |
Public Member Functions inherited from SoftI2cMaster | |
uint8_t | start (uint8_t addressRW) |
void | stop (void) |
uint8_t | restart (uint8_t addressRW) |
uint8_t | write (uint8_t b) |
uint8_t | read (uint8_t last) |
SoftI2cMaster (uint8_t devAddr) | |
void | initProtocol (uint8_t sclPin=(uint8_t) NULL, uint8_t sdaPin=(uint8_t) NULL) |
uint8_t * | readRegisters (uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL) |
bool | writeRegistersWithLocation (int bytes, uint8_t *buf) |
bool | writeRegisters (uint8_t location, uint8_t bytes_to_write, uint8_t *buffer=0) |
bool | writeByte (uint8_t location, uint8_t data) |
bool | writeInteger (uint8_t location, uint16_t data) |
bool | writeLong (uint8_t location, uint32_t data) |
char * | readString (uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL, uint8_t len=0) |
uint8_t | readByte (uint8_t location) |
int16_t | readInteger (uint8_t location) |
uint32_t | readLong (uint8_t location) |
char * | getFirmwareVersion () |
char * | getVendorID () |
char * | getDeviceID () |
uint8_t | getWriteErrorCode () |
bool | checkAddress () |
bool | setAddress (uint8_t address) |
Additional Inherited Members | |
Public Attributes inherited from EVShieldI2C | |
void * | mp_shield |
uint8_t * | _i2c_buffer |
uint8_t | m_protocol |
Public Attributes inherited from SoftI2cMaster | |
uint8_t * | _so_buffer |
Static Public Attributes inherited from BaseI2CDevice | |
static uint8_t * | _buffer = 0 |
static bool | b_initialized = false |
Protected Member Functions inherited from BaseI2CDevice | |
void | setWriteErrorCode (uint8_t code) |
This class defines methods for the EVShield Bank(s).
EVShieldBank::EVShieldBank | ( | uint8_t | i2c_address = SH_Bank_A | ) |
Constructor for bank a of the EVShield device
int EVShieldBank::evshieldGetBatteryVoltage | ( | ) |
Get the battery voltage (milli-volts) for this bank of the EVShield
uint8_t EVShieldBank::EVShieldIssueCommand | ( | char | command | ) |
Issue a command to this bank of the EVShield
command | Refer to user guide for list of commands. |
uint8_t EVShieldBank::motorGetCommandRegA | ( | SH_Motor | which_motor | ) |
Get the command register A
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorGetCommandRegB | ( | SH_Motor | which_motor | ) |
Get the command register B
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motor | Provide which motor to operate on |
int32_t EVShieldBank::motorGetEncoderPosition | ( | SH_Motor | which_motor | ) |
Get the current encoder position of the motor in degrees
which_motor | Provide which motor to operate on |
long EVShieldBank::motorGetEncoderTarget | ( | SH_Motor | which_motor | ) |
Get the target encoder position for the motor
which_motor | Provide which motor to operate on |
int8_t EVShieldBank::motorGetSpeed | ( | SH_Motor | which_motor | ) |
Get the speed of the motor
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorGetStatusByte | ( | SH_Motor | which_motor | ) |
Get the current status of the motor
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorGetTasksRunningByte | ( | SH_Motor | which_motor | ) |
Get the tasks that are running on the specific motor
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorGetTimeToRun | ( | SH_Motor | which_motor | ) |
Get the time in seconds that the motor is running for
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorIsTachoDone | ( | SH_Motor | which_motors | ) |
Validate if the motor has reached its set target tachometer position
which_motors | Provide which motor(s) to operate on |
uint8_t EVShieldBank::motorIsTimeDone | ( | SH_Motor | which_motors | ) |
Validate if the motor has finished running for the set time duration
which_motors | Provide which motor(s) to operate on |
bool EVShieldBank::motorReset | ( | ) |
Reset all the set values for the motors Applies to all motors on this bank.
bool EVShieldBank::motorResetEncoder | ( | SH_Motor | which_motor | ) |
Reset the current encoder position to zero for the motor
which_motor | Provide which motor to operate on |
uint8_t EVShieldBank::motorRunDegrees | ( | SH_Motor | which_motors, |
SH_Direction | direction, | ||
int | speed, | ||
long | degrees, | ||
SH_Completion_Wait | wait_for_completion, | ||
SH_Next_Action | next_action | ||
) |
Run the motor for a set number of degrees and proceed to the next action
which_motors | specifiy the motor(s) to operate on |
direction | specifiy the direction to run the motor |
speed | the speed value (between 0 and 100) |
degrees | The degrees the motor should turn through |
wait_for_completion | whether this API should wait for completion or not |
next_action | for these motor being operated on |
uint8_t EVShieldBank::motorRunRotations | ( | SH_Motor | which_motors, |
SH_Direction | direction, | ||
int | speed, | ||
long | rotations, | ||
SH_Completion_Wait | wait_for_completion, | ||
SH_Next_Action | next_action | ||
) |
Run the motor for a set number of complete rotations and proceed to the next action
which_motors | specifiy the motor(s) to operate on |
direction | specifiy the direction to run the motor |
speed | the speed value (between 0 and 100) |
rotations | The rotations the motor should rotate through |
wait_for_completion | whether this API should wait for completion or not |
next_action | for these motor being operated on |
uint8_t EVShieldBank::motorRunSeconds | ( | SH_Motor | which_motors, |
SH_Direction | direction, | ||
int | speed, | ||
uint8_t | duration, | ||
SH_Completion_Wait | wait_for_completion, | ||
SH_Next_Action | next_action | ||
) |
Run the motor for a set duration at a set speed and do the next action
which_motors | specifiy the motor(s) to operate on |
direction | specifiy the direction to run the motor |
speed | the speed value (between 0 and 100) |
duration | in seconds |
wait_for_completion | whether this API should wait for completion or not |
next_action | for these motor being operated on |
uint8_t EVShieldBank::motorRunTachometer | ( | SH_Motor | which_motors, |
SH_Direction | direction, | ||
int | speed, | ||
long | tachometer, | ||
SH_Move | relative, | ||
SH_Completion_Wait | wait_for_completion, | ||
SH_Next_Action | next_action | ||
) |
run until the tachometer target has been reached and do next action
which_motors | specifiy the motor(s) to operate on |
direction | specifiy the direction to run the motor |
speed | the speed value (between 0 and 100) |
tachometer | the target for the encoder value to achieve. |
relative | is the tachometer relative or absolute. |
wait_for_completion | whether this API should wait for completion or not |
next_action | for these motor being operated on |
void EVShieldBank::motorRunUnlimited | ( | SH_Motor | which_motors, |
SH_Direction | direction, | ||
int | speed | ||
) |
Run the motor endlessly at the desired speed in the desired direction
which_motors | specifiy the motor(s) to operate on |
direction | specifiy the direction to run the motor |
speed | the speed value (between 0 and 100) |
bool EVShieldBank::motorSetCommandRegA | ( | SH_Motor | which_motor, |
uint8_t | value | ||
) |
Set the Command Register A There are two command registers, A and B.
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motor | Provide which motor to operate on |
value | The command register value to set |
bool EVShieldBank::motorSetCommandRegB | ( | SH_Motor | which_motor, |
uint8_t | value | ||
) |
Set the Command Register B There are two command registers, A and B.
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motor | Provide which motor to operate on |
value | The command register value to set |
bool EVShieldBank::motorSetEncoderPID | ( | uint16_t | Kp, |
uint16_t | Ki, | ||
uint16_t | Kd | ||
) |
Set the PID control factors for the encoders All motors on this bank will use the same PID values.
Kp | The proportionate factor of the PID. |
Ki | The integreal factor of the PID. |
Kd | The differential factor of the PID. |
bool EVShieldBank::motorSetEncoderSpeedTimeAndControl | ( | SH_Motor | which_motors, |
long | encoder, | ||
int | speed, | ||
uint8_t | duration, | ||
uint8_t | control | ||
) |
This function sets the speed, the number of seconds, and the control (a.k.a. command register A)
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motors | Provide which motor(s) to operate on |
encoder | Target encoder position to achieve |
speed | Speed value between 0 and 100 |
duration | time to run in seconds |
control | command register value |
bool EVShieldBank::motorSetEncoderTarget | ( | SH_Motor | which_motor, |
long | target | ||
) |
Set the target encoder position for the motor
which_motor | Provide which motor to operate on |
target | Encode value to achieve |
bool EVShieldBank::motorSetPassCount | ( | uint8_t | pass_count | ) |
Set how many times the PID controller is allowed to oscillate at the set point Depending on your situation of load and power characteristics, your PID algorithm may oscillate indefinitly trying to achieve it's target. To prevent that from happening there is a limit set.
pass_count | the maximum number of times the PID is allowed to cross it's target. |
bool EVShieldBank::motorSetSpeed | ( | SH_Motor | which_motor, |
int | speed | ||
) |
Set the speed of the motor
which_motor | Provide which motor to operate on |
speed | The speed value between 0 and 100 |
bool EVShieldBank::motorSetSpeedPID | ( | uint16_t | Kp, |
uint16_t | Ki, | ||
uint16_t | Kd | ||
) |
Set the PID control factors for the speed of the motors All motors on this bank will use the same PID values.
Kp | The proportionate factor of the PID. |
Ki | The integreal factor of the PID. |
Kd | The differential factor of the PID. |
bool EVShieldBank::motorSetSpeedTimeAndControl | ( | SH_Motor | which_motors, |
int | speed, | ||
uint8_t | duration, | ||
uint8_t | control | ||
) |
Set the speed, duration to run, and control for the motor through register A (or B)
For more information on what register does, please refer to 'Motor Command Register Explained' section of EVShield-Advanced-Development-Guide.pdf from following url: http://www.openelectrons.com/index.php?module=documents&JAS_DocumentManager_op=viewDocument&JAS_Document_id=1
which_motors | Provide which motor(s) to operate on |
speed | Speed value between 0 and 100 |
duration | time to run in seconds |
control | command register value |
bool EVShieldBank::motorSetTimeToRun | ( | SH_Motor | which_motor, |
int | seconds | ||
) |
Set the time in seconds for which the motor should run for
which_motor | Provide which motor to operate on |
seconds | The time duration the motor should run |
bool EVShieldBank::motorSetTolerance | ( | uint8_t | tolerance | ) |
Set how far away from the set point the PID controller is allowed to oscillate (amplitude) Depending on your situation of load and power characteristics, your PID algorithm may oscillate above or below the target.
tolerance | the maximum amplititude allowed. |
bool EVShieldBank::motorStartBothInSync | ( | ) |
Start both motors at the same time to follow the set conditions This will execute the commands specified in the command register on both motors at once.
bool EVShieldBank::motorStop | ( | SH_Motor | which_motors, |
SH_Next_Action | next_action | ||
) |
stop the motor and do the next action
which_motors | specifiy the motor(s) to operate on |
next_action | for these motor being operated on |
uint8_t EVShieldBank::motorWaitUntilTachoDone | ( | SH_Motor | which_motors | ) |
Wait until the motor has reached its set target tachometer position
which_motors | Provide which motor(s) to operate on |
uint8_t EVShieldBank::motorWaitUntilTimeDone | ( | SH_Motor | which_motors | ) |
Wait until the motor has finished running for its set respective time duration
which_motors | Provide which motor(s) to operate on |
int EVShieldBank::nxshieldGetBatteryVoltage | ( | ) |
nxshieldGetBatteryVoltage() is provided for backword compatibility with nxshield programs.
int EVShieldBank::sensorReadRaw | ( | uint8_t | which_sensor | ) |
Read the raw analog value from the sensor and return as an int
which_sensor | the sensor to read the raw value from |
bool EVShieldBank::sensorSetType | ( | uint8_t | which_sensor, |
uint8_t | sensor_type | ||
) |
Set the sensor type of the sensor on this bank
which_sensor | the sensor to set the type to. |
sensor_type | type value of the sensor, refer to Advanced User Guide for available values of sensor types. |