transduino.ino

The Arduino code for the Transnavigators’ Voice Controlled Wheelchair.

Transduino is Arduino code written for the Transnavigators’ Voice Controlled Wheelchair. It supports communication with a Raspberry Pi over I2C, with the Raspberry Pi configured as the master and the Arduino as the slave. Over the interface, the Arduino accepts requests for setting the desired speeds of each motor and requests for getting the current counts of each encoder. The Arduino interfaces with a Sabertooth 2x60 motor controller using a UART interface and a Dual LS7366R Quadrature Encoder Buffer using SPI.

Author
Transnavigators

Defines

SLAVE_ADDRESS

The I2C address of the Arduino.

BAUD_RATE

The serial baud rate for debug messages and Sabertooth communication.

SABERTOOTH_ADDRESS

The current address of the motor controller.

The address can be changed using the switches on the motor controller

ENCODER1_SELECT_PIN

The left encoder select pin number.

ENCODER2_SELECT_PIN

The right encoder select pin number.

SW_SERIAL_PORT

The digital pin to use software serial with for debug mode.

MOVE_COMMAND_SIZE

The number of bytes a command from the motor should be.

1 byte for the motor command and 8 bytes for the motor speeds (2 floats, 4 bytes each)

MOVE_COMMAND

The command byte for a move command.

MOVE_TIMEOUT

The number of microseconds without receiving a command which will cause the chair to stop moving.

PULSES_PER_METER

The number of encoder pulses per meter (6 inch wheel diameter)

4096 pulses per revolution / (2*pi*(6 inches/2) * 0.0254 inches/meter)

LOOP_DELAY

5 ms delay for prod

Typedefs

typedef struct EncoderDataTag EncoderData

Define DEBUG to turn on debug mode.

Defining DEBUG switches communication with the motor controller to software serial Connect S1 of the Sabertooth to Pin SW_SERIAL_PORT in debug mode Connect S1 of the Sabertooth to Pin 1 when not in debug mode A struct to send both encoder counts over SPI

typedef union FloatUnionTag FloatUnion

A union for retrieving floats over I2C.

Functions

Sabertooth ST(SABERTOOTH_ADDRESS)
Encoder_Buffer Encoder1(ENCODER1_SELECT_PIN)
Encoder_Buffer Encoder2(ENCODER2_SELECT_PIN)
void setup()

Setup routine.

void loop()

Main loop.

void receiveData(int byteCount)

Callback for receiving I2C data.

This function only accepts messages in the following format:

Parameters
  • byteCount: the number of bytes received

void sendData()

Callback for i2c data request.

Sends the current counts of the encoder. Response is in the form:

Variables

volatile float Motor1Speed = 0

The desired speed of the left motor.

volatile float Motor2Speed = 0

The desired speed of the right motor.

int8_t Motor1Power = 0

The current power of the left motor.

int8_t Motor2Power = 0

The current power of the right motor.

uint32_t LastPiCommandTime = 0

The last time a message was received.

Used to timeout the arduino after MOVE_TIMEOUT microseconds

uint32_t PreviousLoopTime = 0

The timestamp of the last iteration of the loop.

EncoderData data

Holds current counts for the encoder.

struct EncoderDataTag

Define DEBUG to turn on debug mode.

Defining DEBUG switches communication with the motor controller to software serial Connect S1 of the Sabertooth to Pin SW_SERIAL_PORT in debug mode Connect S1 of the Sabertooth to Pin 1 when not in debug mode A struct to send both encoder counts over SPI

Public Members

int32_t encoder1Count

Count of encoder 1.

int32_t encoder2Count

Count of encoder 2.

union FloatUnionTag

A union for retrieving floats over I2C.

Public Members

byte bVal[4]

Byte value.

float fVal

Float value.