EVShield  v1.3
EVShield Library Reference by mindsensors.com
EVShieldBank Class Reference

This class defines methods for the EVShield Bank(s). More...

#include <EVShield.h>

Inheritance diagram for EVShieldBank:
EVShieldI2C BaseI2CDevice SoftI2cMaster EVShieldBankB

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)
 

Detailed Description

This class defines methods for the EVShield Bank(s).

Constructor & Destructor Documentation

§ EVShieldBank()

EVShieldBank::EVShieldBank ( uint8_t  i2c_address = SH_Bank_A)

Constructor for bank a of the EVShield device

Member Function Documentation

§ evshieldGetBatteryVoltage()

int EVShieldBank::evshieldGetBatteryVoltage ( )

Get the battery voltage (milli-volts) for this bank of the EVShield

Returns
voltage value in milli-volts The voltage reported by this function is actual voltage at VIN pin on Arduino This will be lower than your supply voltage due to drops at various points in the circuit. The drop will be different based on where the power source is connected. (i.e. source through EVShield Green connector Vs Arduino black adapater Vs Arduino USB.)

§ EVShieldIssueCommand()

uint8_t EVShieldBank::EVShieldIssueCommand ( char  command)

Issue a command to this bank of the EVShield

Parameters
commandRefer to user guide for list of commands.

§ motorGetCommandRegA()

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
Parameters
which_motorProvide which motor to operate on
Returns
the last set command register value.

§ motorGetCommandRegB()

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
Parameters
which_motorProvide which motor to operate on
Returns
the last set command register value.

§ motorGetEncoderPosition()

int32_t EVShieldBank::motorGetEncoderPosition ( SH_Motor  which_motor)

Get the current encoder position of the motor in degrees

Parameters
which_motorProvide which motor to operate on
Returns
current encoder value

§ motorGetEncoderTarget()

long EVShieldBank::motorGetEncoderTarget ( SH_Motor  which_motor)

Get the target encoder position for the motor

Parameters
which_motorProvide which motor to operate on
Returns
long encoder value that the motor is trying to achieve.

§ motorGetSpeed()

int8_t EVShieldBank::motorGetSpeed ( SH_Motor  which_motor)

Get the speed of the motor

Parameters
which_motorProvide which motor to operate on
Returns
the speed value set to the motor

§ motorGetStatusByte()

uint8_t EVShieldBank::motorGetStatusByte ( SH_Motor  which_motor)

Get the current status of the motor

Parameters
which_motorProvide which motor to operate on
Returns
The current status of the motor. This is a byte with various bits set based on motor's state. Refer to User Guide for details of bits.

§ motorGetTasksRunningByte()

uint8_t EVShieldBank::motorGetTasksRunningByte ( SH_Motor  which_motor)

Get the tasks that are running on the specific motor

Parameters
which_motorProvide which motor to operate on
Returns
The task byte that's currently running for this motor. (Currently only one task is supported.)

§ motorGetTimeToRun()

uint8_t EVShieldBank::motorGetTimeToRun ( SH_Motor  which_motor)

Get the time in seconds that the motor is running for

Parameters
which_motorProvide which motor to operate on
Returns
time the motor has been running since last start.

§ motorIsTachoDone()

uint8_t EVShieldBank::motorIsTachoDone ( SH_Motor  which_motors)

Validate if the motor has reached its set target tachometer position

Parameters
which_motorsProvide which motor(s) to operate on
Returns
0 when motor(s) has completed a encoder based move properly, If the return value is non-zero, either motor has not finished yet or has encountered an error condition.

§ motorIsTimeDone()

uint8_t EVShieldBank::motorIsTimeDone ( SH_Motor  which_motors)

Validate if the motor has finished running for the set time duration

Parameters
which_motorsProvide which motor(s) to operate on
Returns
0 when motor(s) has completed a timed move properly, If the return value is non-zero, either motor has not finished yet or has encountered an error condition.

§ motorReset()

bool EVShieldBank::motorReset ( )

Reset all the set values for the motors Applies to all motors on this bank.

§ motorResetEncoder()

bool EVShieldBank::motorResetEncoder ( SH_Motor  which_motor)

Reset the current encoder position to zero for the motor

Parameters
which_motorProvide which motor to operate on

§ motorRunDegrees()

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

Parameters
which_motorsspecifiy the motor(s) to operate on
directionspecifiy the direction to run the motor
speedthe speed value (between 0 and 100)
degreesThe degrees the motor should turn through
wait_for_completionwhether this API should wait for completion or not
next_actionfor these motor being operated on
Returns
0 if the operation was finished satisfactorily, in case return value is non-zero you should check for the bits for error conditions.

§ motorRunRotations()

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

Parameters
which_motorsspecifiy the motor(s) to operate on
directionspecifiy the direction to run the motor
speedthe speed value (between 0 and 100)
rotationsThe rotations the motor should rotate through
wait_for_completionwhether this API should wait for completion or not
next_actionfor these motor being operated on
Returns
0 if the operation was finished satisfactorily, in case return value is non-zero you should check for the bits for error conditions.

§ motorRunSeconds()

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

Parameters
which_motorsspecifiy the motor(s) to operate on
directionspecifiy the direction to run the motor
speedthe speed value (between 0 and 100)
durationin seconds
wait_for_completionwhether this API should wait for completion or not
next_actionfor these motor being operated on
Returns
0 if the operation was finished satisfactorily, in case return value is non-zero you should check for the bits for error conditions.

§ motorRunTachometer()

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

Parameters
which_motorsspecifiy the motor(s) to operate on
directionspecifiy the direction to run the motor
speedthe speed value (between 0 and 100)
tachometerthe target for the encoder value to achieve.
relativeis the tachometer relative or absolute.
wait_for_completionwhether this API should wait for completion or not
next_actionfor these motor being operated on
Returns
0 if the operation was finished satisfactorily, in case return value is non-zero you should check for the bits for error conditions.

§ motorRunUnlimited()

void EVShieldBank::motorRunUnlimited ( SH_Motor  which_motors,
SH_Direction  direction,
int  speed 
)

Run the motor endlessly at the desired speed in the desired direction

Parameters
which_motorsspecifiy the motor(s) to operate on
directionspecifiy the direction to run the motor
speedthe speed value (between 0 and 100)
Returns
Starts the motors and function returns immediately

§ motorSetCommandRegA()

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
Parameters
which_motorProvide which motor to operate on
valueThe command register value to set

§ motorSetCommandRegB()

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
Parameters
which_motorProvide which motor to operate on
valueThe command register value to set

§ motorSetEncoderPID()

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.

Parameters
KpThe proportionate factor of the PID.
KiThe integreal factor of the PID.
KdThe differential factor of the PID.

§ motorSetEncoderSpeedTimeAndControl()

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
Parameters
which_motorsProvide which motor(s) to operate on
encoderTarget encoder position to achieve
speedSpeed value between 0 and 100
durationtime to run in seconds
controlcommand register value

§ motorSetEncoderTarget()

bool EVShieldBank::motorSetEncoderTarget ( SH_Motor  which_motor,
long  target 
)

Set the target encoder position for the motor

Parameters
which_motorProvide which motor to operate on
targetEncode value to achieve

§ motorSetPassCount()

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.

Parameters
pass_countthe maximum number of times the PID is allowed to cross it's target.

§ motorSetSpeed()

bool EVShieldBank::motorSetSpeed ( SH_Motor  which_motor,
int  speed 
)

Set the speed of the motor

Parameters
which_motorProvide which motor to operate on
speedThe speed value between 0 and 100

§ motorSetSpeedPID()

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.

Parameters
KpThe proportionate factor of the PID.
KiThe integreal factor of the PID.
KdThe differential factor of the PID.

§ motorSetSpeedTimeAndControl()

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
Parameters
which_motorsProvide which motor(s) to operate on
speedSpeed value between 0 and 100
durationtime to run in seconds
controlcommand register value

§ motorSetTimeToRun()

bool EVShieldBank::motorSetTimeToRun ( SH_Motor  which_motor,
int  seconds 
)

Set the time in seconds for which the motor should run for

Parameters
which_motorProvide which motor to operate on
secondsThe time duration the motor should run

§ motorSetTolerance()

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.

Parameters
tolerancethe maximum amplititude allowed.

§ motorStartBothInSync()

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.

§ motorStop()

bool EVShieldBank::motorStop ( SH_Motor  which_motors,
SH_Next_Action  next_action 
)

stop the motor and do the next action

Parameters
which_motorsspecifiy the motor(s) to operate on
next_actionfor these motor being operated on

§ motorWaitUntilTachoDone()

uint8_t EVShieldBank::motorWaitUntilTachoDone ( SH_Motor  which_motors)

Wait until the motor has reached its set target tachometer position

Parameters
which_motorsProvide which motor(s) to operate on
Returns
function waits until when motor(s) has stopped, returns 0 if the set goal was achieved. If the return value is non-zero, you should check for error condition such as stall.

§ motorWaitUntilTimeDone()

uint8_t EVShieldBank::motorWaitUntilTimeDone ( SH_Motor  which_motors)

Wait until the motor has finished running for its set respective time duration

Parameters
which_motorsProvide which motor(s) to operate on
Returns
function waits until when motor(s) has stopped, returns 0 if the set goal was achieved. If the return value is non-zero, you should check for error condition such as stall.

§ nxshieldGetBatteryVoltage()

int EVShieldBank::nxshieldGetBatteryVoltage ( )

nxshieldGetBatteryVoltage() is provided for backword compatibility with nxshield programs.

§ sensorReadRaw()

int EVShieldBank::sensorReadRaw ( uint8_t  which_sensor)

Read the raw analog value from the sensor and return as an int

Parameters
which_sensorthe sensor to read the raw value from
Returns
raw value from the sensor

§ sensorSetType()

bool EVShieldBank::sensorSetType ( uint8_t  which_sensor,
uint8_t  sensor_type 
)

Set the sensor type of the sensor on this bank

Parameters
which_sensorthe sensor to set the type to.
sensor_typetype value of the sensor, refer to Advanced User Guide for available values of sensor types.

The documentation for this class was generated from the following files: