I2CMotorController

From PiE Wiki
Jump to: navigation, search


<< Software

Overview

This is the class you use to control the Polar Bear Motor Controller.

Parents

AcuatorController

MotorController

Children

None

Properties/Fields

//IMPORTANT
//How fast the motor goes. 100 is full forward, -100 is full backwards, 0 is stopped.
//The motors will not move if motorBrake is non-zero.
motorSpeed 
 
//Edit this if you want the motor to brake; it is mostly used in Autonomous mode.
//Default is 0. 0 is no braking, 10 is maximum braking
//If motorBrake is non-zero, then motorSpeed should be 0
motorBrake 
 
//This field controls how fast your motor brakes when inside of the brake range, initially 0
//Has a range from 0 to 255; 0 is full coast, and 255 is full brake
//Change this depending on whether you want your robot to coast or not
brakePower
 
//Changing this field creates a range in which your joystick will brake
//Only use this if you have a joystick that doesn't have good springs and won't return all the way to 127
//Use piemos to find out how much is off then set this to how much it is greater than or less than 127
brakeRange

Methods

Methods to use:

KillActuators(); //stop motors and make it so they can't drive
 
ReviveActuators();//make motors drive-able again

If you call robot.KillActuators or robot.ReviveActuators it will apply the method to all actuators

Methods not to use:

UpdateActuators();

How to Use

Constructor

I2CMotorController i2c = new I2CMotorController(Robot Robo, ushort deviceAdd);

ushort deviceAdd in form 0x0A, drive motors should be 0x0A and 0x0B, non-drive motors should be 0x0C, 0x0D, and all other addresses.

Change speed

 i2c.motorSpeed=constant1;

For Tank Drive

 i2c1.motorSpeed = ((float)(robot.UIAnalogVals[3] - 128) * 100 / (float)128);
 
 i2c2.motorSpeed = -1*((float)(robot.UIAnalogVals[1] - 128) * 100 / (float)128);

i2c1 is right motor and i2c2 is left motor.

Make it brake in Autonomous

 i2c.motorBrake=constant;

Change how fast it brakes

 i2c.brakePower=constant;

Change this if you have a bad joystick

 i2c.brakeRange=constant;

What to use it for

Controlling the Motors

Self contained example