direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Motor Class Reference

Gives access to the motors of the robot. More...

#include <motor.h>

Collaboration diagram for Motor:

List of all members.

Public Slots

void setMaximumSpeed (int speed)
bool setMotorSpeed (int motor, int speed)
void setRobotState (bool state)

Signals

void message (QString text, bool CR=true, bool sayIt=false, bool addTimestamp=true)

Public Member Functions

bool flashlight (bool state)
double getDrivenDistance (unsigned char motor)
int getMotorSpeed (int motor)
unsigned int getRevolutions (unsigned char motor)
 Motor (InterfaceAvr *i, QMutex *m)
bool motorControl (int motor, bool power, int direction)
void resetMovementCounter (short int motor)
 ~Motor ()

Private Member Functions

void calculateMovement ()

Private Attributes

QString className
double drivenDistance1
double drivenDistance2
double drivenDistance3
double drivenDistance4
InterfaceAvrinterface1
int motor1Speed
int motor2Speed
int motor3Speed
int motor4Speed
int motorSpeedAllMotors
QMutex * mutex
 this will contain the name of this class at runtime for debug messages
unsigned int revolutions1
unsigned int revolutions2
unsigned int revolutions3
unsigned int revolutions4
bool robotState

Static Private Attributes

static const int ALLMOTORS = 250
 Motor 4 back right.
static const int BACKWARD = 20
 Motor direction (formerly "clockwise")
static const unsigned char BIT0 = 1
static const unsigned char BIT1 = 2
static const unsigned char BIT2 = 4
static const unsigned char BIT3 = 8
static const unsigned char BIT4 = 16
static const unsigned char BIT5 = 32
static const unsigned char BIT6 = 64
static const unsigned char BIT7 = 128
static const unsigned char BOTBACKWARD = 81
static const unsigned char BOTFORWARD = 80
 The serial driving commands for the robot.
static const unsigned char BOTLEFT = 82
static const unsigned char BOTRIGHT = 83
static const unsigned char BOTSTART = 86
static const unsigned char BOTSTOP = 87
static const unsigned char BOTTURNLEFT = 84
static const unsigned char BOTTURNRIGHT = 85
static const unsigned char BOTWAIT = 88
static const char CLOCK = 1
static const unsigned char FLASHLIGHT_OFF = 40
static const unsigned char FLASHLIGHT_ON = 41
static const int FORWARD = 10
 Some driving directions and motor directions for the robot.
static const unsigned char HIGH = 1
static const int LEFT = 30
 Motor direction (formerly "counterclockwise".
static const unsigned char LOW = 0
static const int MOTOR1 = 210
 Motor direction/power "same like before".
static const unsigned char MOTOR1_CLOCKWISE = 21
static const unsigned char MOTOR1_COUNTERCLOCKWISE = 22
static const unsigned char MOTOR1_OFF = 20
 the "serial" commands for the MC -> see "main.h" in the microcontroller source code (direcs-avr)!
static const unsigned char MOTOR1_SPEED_SET = 26
static const unsigned char MOTOR1A = BIT0
 The bits for controling the USB-Circuit.
static const unsigned char MOTOR1B = BIT1
static const int MOTOR1BW = 310
static const int MOTOR1FW = 300
 used for letting the robot getting only one command for all motors (like 'forward all'). This is to reduce commands on the serial line.
static const int MOTOR1OFF = 320
static const int MOTOR2 = 220
 Motor 1 front left.
static const unsigned char MOTOR2_CLOCKWISE = 24
static const unsigned char MOTOR2_COUNTERCLOCKWISE = 25
static const unsigned char MOTOR2_OFF = 23
static const unsigned char MOTOR2_SPEED_SET = 27
static const unsigned char MOTOR2A = BIT2
static const unsigned char MOTOR2B = BIT3
static const int MOTOR2BW = 340
static const int MOTOR2FW = 330
static const int MOTOR2OFF = 350
static const int MOTOR3 = 230
 Motor 2 front right.
static const unsigned char MOTOR3_CLOCKWISE = 51
static const unsigned char MOTOR3_COUNTERCLOCKWISE = 52
static const unsigned char MOTOR3_OFF = 50
static const unsigned char MOTOR3_SPEED_SET = 56
static const int MOTOR3BW = 370
static const int MOTOR3FW = 360
static const int MOTOR3OFF = 380
static const int MOTOR4 = 240
 Motor 3 back left.
static const unsigned char MOTOR4_CLOCKWISE = 54
static const unsigned char MOTOR4_COUNTERCLOCKWISE = 55
static const unsigned char MOTOR4_OFF = 53
static const unsigned char MOTOR4_SPEED_SET = 57
static const int MOTOR4BW = 400
static const int MOTOR4FW = 390
static const int MOTOR4OFF = 410
static const unsigned char MOTORCLOCK = BIT4
static const char OFF = false
static const char ON = true
static const int READ_AXIS_X = 500
static const int READ_AXIS_Y = 510
static const int READ_AXIS_Z = 520
static const int RIGHT = 40
static const int SAME = 200
static const unsigned char SPEED_SET_ALLMOTORS = 60
static const int START = 70
static const int STOP = 80
static const int TURNLEFT = 50
static const int TURNRIGHT = 60
static const int WAIT = 90

Detailed Description

Gives access to the motors of the robot.

Author:
Markus Knapp The Motor class gives access to the motors of the robot.

Definition at line 37 of file motor.h.


Constructor & Destructor Documentation

Motor::Motor ( InterfaceAvr i,
QMutex *  m 
)

Definition at line 23 of file motor.cpp.

Motor::~Motor ( )

Definition at line 59 of file motor.cpp.


Member Function Documentation

void Motor::calculateMovement ( )
private

Definition at line 821 of file motor.cpp.

bool Motor::flashlight ( bool  state)

Turns the flashlight ON or OFF.

Parameters:
statecan be ON or OFF.
Todo:
put this somewhere else...

Definition at line 1177 of file motor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

double Motor::getDrivenDistance ( unsigned char  motor)

Returns the driven distance, if the motor is a stepper motor!

Parameters:
motoris the motor number.
Returns:
The driven distance in cm made of a whee1.

Definition at line 104 of file motor.cpp.

int Motor::getMotorSpeed ( int  motor)
Returns:
The speed of a motor.
Parameters:
motoris the motor number.

Definition at line 1155 of file motor.cpp.

Here is the caller graph for this function:

unsigned int Motor::getRevolutions ( unsigned char  motor)
Parameters:
motoris the motor number.
Returns:
The revolutions made of a motor (stored in the microcontroller till power off).

Definition at line 82 of file motor.cpp.

void Motor::message ( QString  text,
bool  CR = true,
bool  sayIt = false,
bool  addTimestamp = true 
)
signal

Emits a string to the GUI log / console.

See also:
Gui::appendLog()
Parameters:
textis the message to be emitted
CRis true when a CR/LF should be added at the end of the line (default)
sayItis true when the text for the log also should be spoken (default=false)
addTimestampIf true, the a timestamp is added in front of the text. This parameter is optional.

Here is the caller graph for this function:

bool Motor::motorControl ( int  motor,
bool  power,
int  direction 
)

Controls a motor (normal and stepper!).

Parameters:
motoris the motor number.
powercan be ON or OFF.
directioncan be CLOCKWISE or COUNTERCLOCKWISE.
Returns:
true on access (answer from Atmel was okay)
See also:
makeSteps() for generating steps for stepper motors

Definition at line 126 of file motor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Motor::resetMovementCounter ( short int  motor)

Resets the stored driven distances and made revolutions in this class and in the microcontroller.

Parameters:
motoris the motor number.

Definition at line 936 of file motor.cpp.

void Motor::setMaximumSpeed ( int  speed)
slot

Sets the maximum speed of alls motors (the robot).

Parameters:
speedis the speed (0 - 255).

Definition at line 1148 of file motor.cpp.

bool Motor::setMotorSpeed ( int  motor,
int  speed 
)
slot

Sets the speed of a motor.

Parameters:
motoris the motor number (MOTOR1, MOTOR2, MOTOR3, MOTOR4, ALLMOTORS).
speedis the speed (0 - 255). return true on success
Todo:
check if this max value is okay, since we have an int here now. sa: direcsAcr for max values!

Definition at line 996 of file motor.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Motor::setRobotState ( bool  state)
slot

This slots takes the robot (circuit) state, to know if the robot is ON or OFF. When the class knows this, unnecessary communication with the interface can be avoided.

Parameters:
statecan be ON or OFF

Definition at line 1239 of file motor.cpp.

Here is the call graph for this function:


Member Data Documentation

const int Motor::ALLMOTORS = 250
staticprivate

Motor 4 back right.

Definition at line 197 of file motor.h.

const int Motor::BACKWARD = 20
staticprivate

Motor direction (formerly "clockwise")

Definition at line 179 of file motor.h.

const unsigned char Motor::BIT0 = 1
staticprivate

Definition at line 168 of file motor.h.

const unsigned char Motor::BIT1 = 2
staticprivate

Definition at line 169 of file motor.h.

const unsigned char Motor::BIT2 = 4
staticprivate

Definition at line 170 of file motor.h.

const unsigned char Motor::BIT3 = 8
staticprivate

Definition at line 171 of file motor.h.

const unsigned char Motor::BIT4 = 16
staticprivate

Definition at line 172 of file motor.h.

const unsigned char Motor::BIT5 = 32
staticprivate

Definition at line 173 of file motor.h.

const unsigned char Motor::BIT6 = 64
staticprivate

Definition at line 174 of file motor.h.

const unsigned char Motor::BIT7 = 128
staticprivate

Definition at line 175 of file motor.h.

const unsigned char Motor::BOTBACKWARD = 81
staticprivate

Definition at line 250 of file motor.h.

const unsigned char Motor::BOTFORWARD = 80
staticprivate

The serial driving commands for the robot.

Definition at line 249 of file motor.h.

const unsigned char Motor::BOTLEFT = 82
staticprivate

Definition at line 251 of file motor.h.

const unsigned char Motor::BOTRIGHT = 83
staticprivate

Definition at line 252 of file motor.h.

const unsigned char Motor::BOTSTART = 86
staticprivate

Definition at line 255 of file motor.h.

const unsigned char Motor::BOTSTOP = 87
staticprivate

Definition at line 256 of file motor.h.

const unsigned char Motor::BOTTURNLEFT = 84
staticprivate

Definition at line 253 of file motor.h.

const unsigned char Motor::BOTTURNRIGHT = 85
staticprivate

Definition at line 254 of file motor.h.

const unsigned char Motor::BOTWAIT = 88
staticprivate

Definition at line 257 of file motor.h.

QString Motor::className
private
Todo:
check the conversion value and make it a const!

Definition at line 140 of file motor.h.

const char Motor::CLOCK = 1
staticprivate

For motor "OFF"

Definition at line 163 of file motor.h.

double Motor::drivenDistance1
private

Definition at line 156 of file motor.h.

double Motor::drivenDistance2
private

Definition at line 157 of file motor.h.

double Motor::drivenDistance3
private

Definition at line 158 of file motor.h.

double Motor::drivenDistance4
private

Definition at line 159 of file motor.h.

const unsigned char Motor::FLASHLIGHT_OFF = 40
staticprivate

Definition at line 263 of file motor.h.

const unsigned char Motor::FLASHLIGHT_ON = 41
staticprivate

Definition at line 264 of file motor.h.

const int Motor::FORWARD = 10
staticprivate

Some driving directions and motor directions for the robot.

See also:
Direcs::drive() [Slot]

Definition at line 178 of file motor.h.

const unsigned char Motor::HIGH = 1
staticprivate

For stepper motor steps (clock)

Definition at line 165 of file motor.h.

InterfaceAvr* Motor::interface1
private

Definition at line 142 of file motor.h.

const int Motor::LEFT = 30
staticprivate

Motor direction (formerly "counterclockwise".

Definition at line 180 of file motor.h.

const unsigned char Motor::LOW = 0
staticprivate

Definition at line 166 of file motor.h.

const int Motor::MOTOR1 = 210
staticprivate

Motor direction/power "same like before".

Definition at line 193 of file motor.h.

const unsigned char Motor::MOTOR1_CLOCKWISE = 21
staticprivate

Definition at line 227 of file motor.h.

const unsigned char Motor::MOTOR1_COUNTERCLOCKWISE = 22
staticprivate

Definition at line 228 of file motor.h.

const unsigned char Motor::MOTOR1_OFF = 20
staticprivate

the "serial" commands for the MC -> see "main.h" in the microcontroller source code (direcs-avr)!

Definition at line 226 of file motor.h.

const unsigned char Motor::MOTOR1_SPEED_SET = 26
staticprivate

Definition at line 233 of file motor.h.

const unsigned char Motor::MOTOR1A = BIT0
staticprivate

The bits for controling the USB-Circuit.

Definition at line 219 of file motor.h.

const unsigned char Motor::MOTOR1B = BIT1
staticprivate

Definition at line 220 of file motor.h.

const int Motor::MOTOR1BW = 310
staticprivate

Definition at line 200 of file motor.h.

const int Motor::MOTOR1FW = 300
staticprivate

used for letting the robot getting only one command for all motors (like 'forward all'). This is to reduce commands on the serial line.

Definition at line 199 of file motor.h.

const int Motor::MOTOR1OFF = 320
staticprivate

Definition at line 201 of file motor.h.

int Motor::motor1Speed
private

Definition at line 144 of file motor.h.

const int Motor::MOTOR2 = 220
staticprivate

Motor 1 front left.

Definition at line 194 of file motor.h.

const unsigned char Motor::MOTOR2_CLOCKWISE = 24
staticprivate

Definition at line 230 of file motor.h.

const unsigned char Motor::MOTOR2_COUNTERCLOCKWISE = 25
staticprivate

Definition at line 231 of file motor.h.

const unsigned char Motor::MOTOR2_OFF = 23
staticprivate

Definition at line 229 of file motor.h.

const unsigned char Motor::MOTOR2_SPEED_SET = 27
staticprivate

Definition at line 234 of file motor.h.

const unsigned char Motor::MOTOR2A = BIT2
staticprivate

Definition at line 221 of file motor.h.

const unsigned char Motor::MOTOR2B = BIT3
staticprivate

Definition at line 222 of file motor.h.

const int Motor::MOTOR2BW = 340
staticprivate

Definition at line 203 of file motor.h.

const int Motor::MOTOR2FW = 330
staticprivate

Definition at line 202 of file motor.h.

const int Motor::MOTOR2OFF = 350
staticprivate

Definition at line 204 of file motor.h.

int Motor::motor2Speed
private

Definition at line 145 of file motor.h.

const int Motor::MOTOR3 = 230
staticprivate

Motor 2 front right.

Definition at line 195 of file motor.h.

const unsigned char Motor::MOTOR3_CLOCKWISE = 51
staticprivate

Definition at line 237 of file motor.h.

const unsigned char Motor::MOTOR3_COUNTERCLOCKWISE = 52
staticprivate

Definition at line 238 of file motor.h.

const unsigned char Motor::MOTOR3_OFF = 50
staticprivate

Definition at line 236 of file motor.h.

const unsigned char Motor::MOTOR3_SPEED_SET = 56
staticprivate

Definition at line 243 of file motor.h.

const int Motor::MOTOR3BW = 370
staticprivate

Definition at line 206 of file motor.h.

const int Motor::MOTOR3FW = 360
staticprivate

Definition at line 205 of file motor.h.

const int Motor::MOTOR3OFF = 380
staticprivate

Definition at line 207 of file motor.h.

int Motor::motor3Speed
private

Definition at line 146 of file motor.h.

const int Motor::MOTOR4 = 240
staticprivate

Motor 3 back left.

Definition at line 196 of file motor.h.

const unsigned char Motor::MOTOR4_CLOCKWISE = 54
staticprivate

Definition at line 240 of file motor.h.

const unsigned char Motor::MOTOR4_COUNTERCLOCKWISE = 55
staticprivate

Definition at line 241 of file motor.h.

const unsigned char Motor::MOTOR4_OFF = 53
staticprivate

Definition at line 239 of file motor.h.

const unsigned char Motor::MOTOR4_SPEED_SET = 57
staticprivate

Definition at line 244 of file motor.h.

const int Motor::MOTOR4BW = 400
staticprivate

Definition at line 209 of file motor.h.

const int Motor::MOTOR4FW = 390
staticprivate

Definition at line 208 of file motor.h.

const int Motor::MOTOR4OFF = 410
staticprivate

Definition at line 210 of file motor.h.

int Motor::motor4Speed
private

Definition at line 147 of file motor.h.

const unsigned char Motor::MOTORCLOCK = BIT4
staticprivate

Definition at line 223 of file motor.h.

int Motor::motorSpeedAllMotors
private

Definition at line 148 of file motor.h.

QMutex* Motor::mutex
mutableprivate

this will contain the name of this class at runtime for debug messages

Definition at line 141 of file motor.h.

const char Motor::OFF = false
staticprivate

For motor "ON"

Definition at line 162 of file motor.h.

const char Motor::ON = true
staticprivate

Definition at line 161 of file motor.h.

const int Motor::READ_AXIS_X = 500
staticprivate

Definition at line 212 of file motor.h.

const int Motor::READ_AXIS_Y = 510
staticprivate

Definition at line 213 of file motor.h.

const int Motor::READ_AXIS_Z = 520
staticprivate

Definition at line 214 of file motor.h.

unsigned int Motor::revolutions1
private

Definition at line 152 of file motor.h.

unsigned int Motor::revolutions2
private

Definition at line 153 of file motor.h.

unsigned int Motor::revolutions3
private

Definition at line 154 of file motor.h.

unsigned int Motor::revolutions4
private

Definition at line 155 of file motor.h.

const int Motor::RIGHT = 40
staticprivate

Definition at line 181 of file motor.h.

bool Motor::robotState
private

Definition at line 143 of file motor.h.

const int Motor::SAME = 200
staticprivate

Definition at line 192 of file motor.h.

const unsigned char Motor::SPEED_SET_ALLMOTORS = 60
staticprivate

Definition at line 246 of file motor.h.

const int Motor::START = 70
staticprivate

Definition at line 184 of file motor.h.

const int Motor::STOP = 80
staticprivate

Definition at line 185 of file motor.h.

const int Motor::TURNLEFT = 50
staticprivate

Definition at line 182 of file motor.h.

const int Motor::TURNRIGHT = 60
staticprivate

Definition at line 183 of file motor.h.

const int Motor::WAIT = 90
staticprivate

Definition at line 186 of file motor.h.


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