Modules | Enumerations
Motors

Functions which handle the motors. More...

Modules

 Advanced informations
 

Enumerations

enum  eMotorSetMask
 clusters bit masks for writing data to the motors More...
 
enum  eMotorGet
 clusters select values for reading data from the motors More...
 

Request Funktions

void motors_request (eRequestType request)
 Requests new data from the motors. More...
 
uint8_t motors_received (void)
 Indicates if new data for the data block sMD_Motor was received. More...
 
uint8_t motors_changed (void)
 Indicates if new data changed the data block sMD_Motor. More...
 
uint8_t motors_transmitted (void)
 Indicates if the data block sMD_Mode was transmitted. More...
 

Access Funktions

int8_t motors_get (eMotorGet select)
 Returns the last stored power of the selected motor. More...
 
void motors_set (eMotorSetMask select, int8_t power)
 Sets the motor power of the selected motor(s). More...
 

Detailed Description

Functions which handle the motors.

The motors are part of the driving module. All actions, like setting their power level or reading it back, involve internal TWI communication. This may take some milliseconds (delay time).

example

/*******************************************************************************
* examples/motorSimple.c *
* ====================== *
* *
* Version: 1.0.5 *
* Date : 07.11.17 *
* Author : Peter Weissig *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testMotor(void);
int main(void);
//*********************************[testMotor]**********************************
void testMotor(void) {
int8_t speed = 0;
lcdclr();
lcdstr_p(PSTR("Motor ####%"));
lcdxy(0,1);
lcdstr_p(PSTR("####mA ####mA"));
while (1) {
mdelay(100);
if (speed > -100) {
speed-= 5;
lcdxy(11,0);
int16tostr(lcdout,speed , 4);
}
} else if (buttons_get(kButtonRight)) {
mdelay(100);
if (speed < 100) {
speed+= 5;
lcdxy(11,0);
int16tostr(lcdout,speed , 4);
}
}
}
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testMotor();
return (0);
}

Enumeration Type Documentation

◆ eMotorGet

enum eMotorGet

clusters select values for reading data from the motors

See also
motors_get() and eMotorSetMask
Enumerator
kMotorGetLeft 

constant (kMotorSetLeft): left motor

kMotorGetRight 

constant (kMotorSetRight): right motor

◆ eMotorSetMask

clusters bit masks for writing data to the motors

See also
motors_set() and eMotorGet
Enumerator
kMotorSetLeft 

bit mask (0x01): left motor

kMotorSetRight 

bit mask (0x02): right motor

kMotorSetAll 

bit mask (0x03): both motors

Function Documentation

◆ motors_changed()

uint8_t motors_changed ( void  )

Indicates if new data changed the data block sMD_Motor.

The return value is boolean.

Returns
8-bit unsigned integer which is a boolean value
See also
motors_received(), motors_request() and motors_get()

◆ motors_get()

int8_t motors_get ( eMotorGet  select)

Returns the last stored power of the selected motor.

This function relies on the internal data block sMD_Motor - for new data use motors_request().

Parameters
selectvalue of the selected motor - see also eMotorGet
Returns
8-bit integer (-100..100)
The motor power is measured in %.
Negative values relate to a motor turning backwards.
See also
motors_request() and motors_set()
Examples
motorComplex.c.

◆ motors_received()

uint8_t motors_received ( void  )

Indicates if new data for the data block sMD_Motor was received.

The return value is boolean.

Returns
8-bit unsigned integer which is a boolean value
See also
motors_changed(), motors_request() and motors_get()
Examples
motorComplex.c.

◆ motors_request()

void motors_request ( eRequestType  request)

Requests new data from the motors.

For details on the request schema see The general request.

Involved data blocks are:
sMD_Motor

Parameters
requestSee also eRequestType
See also
motors_get()
Examples
motorComplex.c.

◆ motors_set()

void motors_set ( eMotorSetMask  select,
int8_t  power 
)

Sets the motor power of the selected motor(s).

This function changes the internal data block sMD_Motor.

Parameters
selectvalue of the selected motor(s) - see also eMotorSetMask
power8-bit integer (-100..100)
The motor power is measured in %.
Negative values relate to a motor turning backwards.
See also
motors_request() and motors_set()
Examples
encoderComplex.c, motorComplex.c, motorSimple.c, and remoteControl.c.

◆ motors_transmitted()

uint8_t motors_transmitted ( void  )

Indicates if the data block sMD_Mode was transmitted.

The return value is boolean.

Returns
8-bit unsigned integer which is a boolean value
See also
motors_set()
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
kCurrentGetRight
@ kCurrentGetRight
constants (2): right motor current
Definition: currents.h:45
kModeStudent
@ kModeStudent
constant (1): robot is in student mode
Definition: mode.h:31
kCurrentGetLeft
@ kCurrentGetLeft
constants (1): left motor current
Definition: currents.h:43
kMotorSetAll
@ kMotorSetAll
bit mask (0x03): both motors
Definition: motors.h:47
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
currents_get
uint16_t currents_get(eCurrentGet select)
Returns the last stored current of the selected motor.
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
int16tostr
void int16tostr(void *out, int16_t number, uint8_t digits)
Converts an integer to a string and passes it to an output function.
currents_changed
uint8_t currents_changed(void)
Indicates if new data changed the data block sMD_SensCurrent.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
lcdclr
void lcdclr(void)
Clears the display.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
mode_set
void mode_set(eMode mode)
Sets the mode of the TUC-Bot.
motors_set
void motors_set(eMotorSetMask select, int8_t power)
Sets the motor power of the selected motor(s).
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
currents_request
void currents_request(eRequestType request)
Requests new data from the motor currents.