ASURO Library  2.80
Macros | Typedefs | Functions | Variables
asuro.h File Reference

Definitionen und Funktionen der ASURO Bibliothek. More...

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <avr/pgmspace.h>
#include <stdlib.h>
Include dependency graph for asuro.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FALSE   0
 
#define TRUE   1
 
#define OFF   0
 
#define ON   1
 
#define GREEN   1
 
#define RED   2
 
#define YELLOW   3
 
#define LEFT   0
 
#define RIGHT   1
 
#define CENTER   2
 
#define K1   (1<<5)
 
#define K2   (1<<4)
 
#define K3   (1<<3)
 
#define K4   (1<<2)
 
#define K5   (1<<1)
 
#define K6   (1<<0)
 
#define ADC_CTRL_WHEEL_LEFT   0
 
#define ADC_CTRL_WHEEL_RIGHT   1
 
#define ADC_CTRL_SWITCHES   2
 
#define ADC_CTRL_IR_LEFT   3
 
#define ADC_CTRL_IR_RIGHT   4
 
#define ADC_CTRL_BATTERIE   5
 
#define ADC_CTRL_SWITCHED   6
 
#define Go(distance, speed)   GoTurn(distance,0,speed)
 
#define Turn(degree, speed)   GoTurn(0,degree,speed)
 
#define Batterie   Battery
 
#define OdometrieData   OdometryData
 
#define SerPrint_P(_str)   SerPrint_p(PSTR(_str))
 
#define GREEN_LED_ON   PORTB |= GREEN_LED
 
#define GREEN_LED_OFF   PORTB &= ~GREEN_LED
 
#define RED_LED_ON   PORTD |= RED_LED
 
#define RED_LED_OFF   PORTD &= ~RED_LED
 
#define FWD   _BV(PB5)
 
#define RWD   _BV(PB4)
 
#define BREAK   0x00
 
#define FREE   _BV(PB4) | _BV(PB5)
 
#define IRTX   _BV(PB3)
 
#define GREEN_LED   _BV(PB0)
 
#define RED_LED   _BV(PD2)
 
#define PWM   _BV(PB1) | _BV(PB2)
 
#define RIGHT_DIR   _BV(PB4) | _BV(PB5)
 
#define LEFT_DIR   _BV(PD4) | _BV(PD5)
 
#define SWITCHES   _BV(PD3)
 
#define SWITCH_ON   PORTD |= SWITCHES
 
#define SWITCH_OFF   PORTD &= ~SWITCHES
 
#define BATTERIE   _BV(MUX0) | _BV(MUX2)
 
#define SWITCH   _BV(MUX2)
 
#define IR_LEFT   _BV(MUX0) | _BV(MUX1)
 
#define IR_RIGHT   _BV(MUX1)
 
#define FRONT_LED   _BV(PD6)
 
#define ODOMETRIE_LED   _BV(PD7)
 
#define ODOMETRIE_LED_ON   PORTD |= ODOMETRIE_LED
 
#define ODOMETRIE_LED_OFF   PORTD &= ~ODOMETRIE_LED
 
#define WHEEL_LEFT   _BV(MUX0)
 
#define WHEEL_RIGHT   0
 

Typedefs

typedef void(* voidFuncPtr )(void)
 

Functions

void Init (void)
 
unsigned long Gettime (void)
 return time since system start in ms
 
void Msleep (unsigned int ms)
 sleep function (ms)
 
void Sleep (unsigned char time36kHz)
 sleep function (36Khz)
 
void EncoderInit (void)
 initialise and starts odometry mesurement uses interrupt(ADC_vect)
 
void EncoderSet (int setl, int setr)
 set odometry tick counter
 
void EncoderStop (void)
 stop counting odometry sensor ticks
 
void EncoderStart (void)
 stop counting odometry sensor ticks
 
void GoTurn (int distance, int degree, int speed)
 moves the robot forward/backward OR turns the robot using the odometry sensors. You can use the old function-names Go() and Turn()
 
int Battery (void)
 returns the battery voltage
 
void LineData (unsigned int *data)
 reads out the phototransistors
 
void OdometryData (unsigned int *data)
 reads out the odometry phototransistors
 
unsigned int ReadADC (unsigned int mux, unsigned int sleep)
 
void StatusLED (unsigned char color)
 controls the StatusLED
 
void FrontLED (unsigned char status)
 controls the FrontLED
 
void BackLED (unsigned char left, unsigned char right)
 values: ON, OFF
 
void MotorDir (unsigned char left_dir, unsigned char right_dir)
 Motor configuration. values: FWD, RWD, BREAK, FREE.
 
void MotorSpeed (unsigned char left_speed, unsigned char right_speed)
 sets motor speed. range: 0..255
 
void MyMotorSpeed (unsigned char left_speed, unsigned char right_speed)
 sets motor speed. range: 0..255
 
void SetMotorPower (int8_t leftpwm, int8_t rightpwm)
 sets motor speed and direcction. range: -128..+128
 
void SerWrite (unsigned char *data, unsigned char length)
 Send Data to UART.
 
void SerRead (unsigned char *data, unsigned char length, unsigned int timeout)
 Receive Data from UART.
 
void UartPutc (unsigned char zeichen)
 Send a single character to UART.
 
void SerPrint (char *data)
 Send a 0-terminated string to UART.
 
void PrintInt (int wert)
 Send a Integer value converted to a string to UART.
 
void PrintLong (long wert)
 Send a Long value converted to a string to UART.
 
void SerPrint_p (const char *data)
 Send a 0-terminated string from program space to UART.
 
void PrintFloat (float wert, char vorkomma, char nachkomma)
 Send a Float value converted to a string to UART.
 
unsigned char PollSwitch (void)
 function to read out switches
 
void StartSwitch (void)
 binds switch press to external Interrupt 1 catch it with ISR(INT1_vect) see avr-libc documentation for details
 
void StopSwitch (void)
 stop sending switch interrupt clears INT1_vect
 
void Sound (uint16_t freq, uint16_t duration_msec, uint8_t amplitude)
 Genrates a sound via the motors.
 

Variables

volatile unsigned int adcValue []
 
const char version [5]
 
volatile int switched
 any switch pressed?
 
volatile int encoder [2]
 odometry sensors tick count access: encoder[LEFT], encoder[RIGHT]
range: 0..255
 
volatile unsigned char count36kHz
 
volatile unsigned long timebase
 
volatile int autoencode
 
volatile voidFuncPtr Ovr2IntFunc
 
volatile voidFuncPtr AdcIntFunc
 

Detailed Description

Definitionen und Funktionen der ASURO Bibliothek.

Revision:
2.70
Date:
07. Januar 2007
Author:
Jan Grewe, Robotrixer, Waste, Stochri, Andun, m.a.r.v.i.n
Version
V001 - 10.02.2007 - m.a.r.v.i.n
+++ my_t Neue Datenstruktur
Datenstruktur fuer die Asuro-Hardwareabhaengigen Parameter die jeder User fuer seinen Asuro in der Datei myasuro.h selber einstellen kann um die Asuro-Typischen Eigenschaften zu definieren.
V002 - 18.02.2007 - Sternthaler
+++ my_t
  • Neue Variable fuer MY_MOTOR_DIFF zum ausgleichen unterschiedlicher
    Motoren.
  • Aendern aller enthaltenen Variablen auf einen moeglichst kleinen
    Speicherbedarf. Notwendige Typumwandlungen muessen im Code durch
    casten erfolgen.
V003 - 20.02.2007 - m.a.r.v.i.n
+++ my_t Datenstruktur wieder entfernt
Es werden direkt die Defines aus der myasuro.h verwendet.
V004 - 06.04.2007 - m.a.r.v.i.n
Batterie und OdometrieData Funktionen umbenannt in Battery und OdometryData.
Alte Funktionsnamen ueber Defines beibehalten
V005 - 07.06.2007 - Sternthaler
Funktionen Go() und Turn() aus encoder.c zusammengefasst in GoTurn().
Alte Funktionsnamen ueber Defines beibehalten
V006 - 11.07.2007 - Sternthaler
Externe Variable encoder als volatile angegeben, da sie im Interrupt SIGNAL (SIG_ADC) benutzt wird.
V007 - 15.11.2007 - m.a.r.v.i.n
Variable switched als volatile definiert, da sie im Interrupt SIGNAL (SIG_INTERRUPT1) benutzt wird.
V008 - 29.03.2009 - rossir
A/D Wandler Abfrage ueber Interrupt.
V009 - 26.03.2010 - Sternthaler
+++ Msleep()
Parameter von "int" auf "unsigned int" umgestellt. (Tip von Valen)

Definition in file asuro.h.

Macro Definition Documentation

#define ADC_CTRL_BATTERIE   5

Definition at line 282 of file asuro.h.

#define ADC_CTRL_IR_LEFT   3

Definition at line 280 of file asuro.h.

#define ADC_CTRL_IR_RIGHT   4

Definition at line 281 of file asuro.h.

#define ADC_CTRL_SWITCHED   6

Definition at line 283 of file asuro.h.

#define ADC_CTRL_SWITCHES   2

Definition at line 279 of file asuro.h.

#define ADC_CTRL_WHEEL_LEFT   0

Definition at line 277 of file asuro.h.

#define ADC_CTRL_WHEEL_RIGHT   1

Definition at line 278 of file asuro.h.

#define Batterie   Battery

Definition at line 440 of file asuro.h.

#define BATTERIE   _BV(MUX0) | _BV(MUX2)

ADC5 A/D Wandler Port fuer Batterie Abfrage

Definition at line 616 of file asuro.h.

#define BREAK   0x00

Motor bremsen

Definition at line 601 of file asuro.h.

#define CENTER   2

Definition at line 258 of file asuro.h.

#define FALSE   0

Definition at line 245 of file asuro.h.

#define FREE   _BV(PB4) | _BV(PB5)

Motor freilaufend

Definition at line 602 of file asuro.h.

#define FRONT_LED   _BV(PD6)

PD6 Port fuer Front LED

Definition at line 620 of file asuro.h.

#define FWD   _BV(PB5)

Motor vorwaerts

Definition at line 599 of file asuro.h.

#define Go (   distance,
  speed 
)    GoTurn(distance,0,speed)

Definition at line 414 of file asuro.h.

#define GREEN   1

Definition at line 251 of file asuro.h.

#define GREEN_LED   _BV(PB0)

PB0 Port fuer Gruene Status LED

Definition at line 605 of file asuro.h.

#define GREEN_LED_OFF   PORTB &= ~GREEN_LED

Gruene Status LED aus

Definition at line 595 of file asuro.h.

#define GREEN_LED_ON   PORTB |= GREEN_LED

Gruene Status LED an

Definition at line 594 of file asuro.h.

#define IR_LEFT   _BV(MUX0) | _BV(MUX1)

ADC3 A/D Wandler Port fuer Linienfolger Fototransistor links

Definition at line 618 of file asuro.h.

#define IR_RIGHT   _BV(MUX1)

ADC2 A/D Wandler Port fuer Linienfolger Fototransistor rechts

Definition at line 619 of file asuro.h.

#define IRTX   _BV(PB3)

PB3 Port fuer Infrarot Transmitter LED

Definition at line 604 of file asuro.h.

#define K1   (1<<5)

Definition at line 263 of file asuro.h.

#define K2   (1<<4)

Definition at line 264 of file asuro.h.

#define K3   (1<<3)

Definition at line 265 of file asuro.h.

#define K4   (1<<2)

Definition at line 266 of file asuro.h.

#define K5   (1<<1)

Definition at line 267 of file asuro.h.

#define K6   (1<<0)

Definition at line 268 of file asuro.h.

#define LEFT   0

Definition at line 256 of file asuro.h.

#define LEFT_DIR   _BV(PD4) | _BV(PD5)

PD4, PD5 Ports fuer Drehrichtung linker Motor

Definition at line 610 of file asuro.h.

#define ODOMETRIE_LED   _BV(PD7)

PD7 Port fuer Odometrie LED

Definition at line 622 of file asuro.h.

#define ODOMETRIE_LED_OFF   PORTD &= ~ODOMETRIE_LED

Odometrie LED aus

Definition at line 624 of file asuro.h.

#define ODOMETRIE_LED_ON   PORTD |= ODOMETRIE_LED

Odometrie LED an

Definition at line 623 of file asuro.h.

#define OdometrieData   OdometryData

Definition at line 441 of file asuro.h.

#define OFF   0

Definition at line 248 of file asuro.h.

#define ON   1

Definition at line 249 of file asuro.h.

#define PWM   _BV(PB1) | _BV(PB2)

PB1, PB2 Ports fuer Pulsweitenmodulation der Motor Geschwindigkeit

Definition at line 608 of file asuro.h.

#define RED   2

Definition at line 252 of file asuro.h.

#define RED_LED   _BV(PD2)

PD2 Port fuer Rote Status LED

Definition at line 606 of file asuro.h.

#define RED_LED_OFF   PORTD &= ~RED_LED

Rote Status LED aus

Definition at line 597 of file asuro.h.

#define RED_LED_ON   PORTD |= RED_LED

Rote Status LED an

Definition at line 596 of file asuro.h.

#define RIGHT   1

Definition at line 257 of file asuro.h.

#define RIGHT_DIR   _BV(PB4) | _BV(PB5)

PB4, PB5 Ports fuer Drehrichtung rechter Motor

Definition at line 609 of file asuro.h.

#define RWD   _BV(PB4)

Motor rueckwaerts

Definition at line 600 of file asuro.h.

#define SerPrint_P (   _str)    SerPrint_p(PSTR(_str))

Definition at line 547 of file asuro.h.

#define SWITCH   _BV(MUX2)

ADC4 A/D Wandler Port fuer Tastsensor

Definition at line 617 of file asuro.h.

#define SWITCH_OFF   PORTD &= ~SWITCHES

Tastsensor aus

Definition at line 614 of file asuro.h.

#define SWITCH_ON   PORTD |= SWITCHES

Tastsensor an

Definition at line 613 of file asuro.h.

#define SWITCHES   _BV(PD3)

PD3 Port fuer Tastsensor

Definition at line 612 of file asuro.h.

#define TRUE   1

Definition at line 246 of file asuro.h.

#define Turn (   degree,
  speed 
)    GoTurn(0,degree,speed)

Definition at line 415 of file asuro.h.

#define WHEEL_LEFT   _BV(MUX0)

ADC1 A/D Wandler Port fuer Odometrie Sensor links

Definition at line 626 of file asuro.h.

#define WHEEL_RIGHT   0

ADC0 A/D Wandler Port fuer Odometrie Sensor rechts

Definition at line 627 of file asuro.h.

#define YELLOW   3

Definition at line 253 of file asuro.h.

Typedef Documentation

typedef void(* voidFuncPtr)(void)

Definition at line 343 of file asuro.h.

Function Documentation

void BackLED ( unsigned char  left,
unsigned char  right 
)

values: ON, OFF

Parameters
leftleftLED status
rightrightLED status
int Battery ( void  )

returns the battery voltage

Returns
ADC value. range: 0..1023
void EncoderInit ( void  )

initialise and starts odometry mesurement uses interrupt(ADC_vect)

void EncoderSet ( int  setl,
int  setr 
)

set odometry tick counter

Parameters
setlleft tick counter
setrleft tick counter
void EncoderStart ( void  )

stop counting odometry sensor ticks

void EncoderStop ( void  )

stop counting odometry sensor ticks

void FrontLED ( unsigned char  status)

controls the FrontLED

Parameters
statusvalues: ON, OFF
unsigned long Gettime ( void  )

return time since system start in ms

Returns
current system time in ms
void GoTurn ( int  distance,
int  degree,
int  speed 
)

moves the robot forward/backward OR turns the robot using the odometry sensors. You can use the old function-names Go() and Turn()

Parameters
distancetravalling distance in cm. positive = forward, negative = backward if distanse is zero, then the function will work as Turn.
degreedegrees to turn. positive = turn right, negative = turn left. range: -360..360
speedmotor speed. range: 0..255
void Init ( void  )

initialises the hardware (ports, ADC, PWM) this function has to be called by every program first

void LineData ( unsigned int *  data)

reads out the phototransistors

Parameters
datapointer to the data destination. access: data[LEFT], data[RIGHT]
void MotorDir ( unsigned char  left_dir,
unsigned char  right_dir 
)

Motor configuration. values: FWD, RWD, BREAK, FREE.

Parameters
left_dirleft motor direction
right_dirright motor direction
void MotorSpeed ( unsigned char  left_speed,
unsigned char  right_speed 
)

sets motor speed. range: 0..255

Parameters
left_speedleft motor
right_speedright motor
void Msleep ( unsigned int  ms)

sleep function (ms)

Parameters
mstime in ms
void MyMotorSpeed ( unsigned char  left_speed,
unsigned char  right_speed 
)

sets motor speed. range: 0..255

Parameters
left_speedleft motor speed
right_speedright motor speed
void OdometryData ( unsigned int *  data)

reads out the odometry phototransistors

Parameters
datapointer to the data destination. access: data[LEFT], data[RIGHT]
unsigned char PollSwitch ( void  )

function to read out switches

Returns
bitfield of switch value bit0 = K6, ... , bit5 = K1
void PrintFloat ( float  wert,
char  vorkomma,
char  nachkomma 
)

Send a Float value converted to a string to UART.

Parameters
wertfloat value
vorkommanumber of chars before the commata
nachkommanumber of chars behind the commata
void PrintInt ( int  wert)

Send a Integer value converted to a string to UART.

Parameters
wertInteger value
void PrintLong ( long  wert)

Send a Long value converted to a string to UART.

Parameters
wertlong value
unsigned int ReadADC ( unsigned int  mux,
unsigned int  sleep 
)
void SerPrint ( char *  data)

Send a 0-terminated string to UART.

Parameters
dataPointer to string
void SerPrint_p ( const char *  data)

Send a 0-terminated string from program space to UART.

Parameters
dataPointer to string
void SerRead ( unsigned char *  data,
unsigned char  length,
unsigned int  timeout 
)

Receive Data from UART.

Parameters
datapointer to data
lengthdata count
timeoutcount, 0 meens blocking mode
void SerWrite ( unsigned char *  data,
unsigned char  length 
)

Send Data to UART.

Parameters
datapointer to data
lengthdata count
void SetMotorPower ( int8_t  leftpwm,
int8_t  rightpwm 
)

sets motor speed and direcction. range: -128..+128

Parameters
leftpwmleft motor speed (negative sign meens backward)
rightpwmright motor speed (negative sign meens backward)
void Sleep ( unsigned char  time36kHz)

sleep function (36Khz)

Parameters
time36kHztime in 1/36k (sec)
void Sound ( uint16_t  freq,
uint16_t  duration_msec,
uint8_t  amplitude 
)

Genrates a sound via the motors.

Parameters
freqfrequence
duration_msecduration in milli seconds
amplitudeamplitude
void StartSwitch ( void  )

binds switch press to external Interrupt 1 catch it with ISR(INT1_vect) see avr-libc documentation for details

void StatusLED ( unsigned char  color)

controls the StatusLED

Parameters
colorvalues: OFF, GREEN, RED, YELLOW
void StopSwitch ( void  )

stop sending switch interrupt clears INT1_vect

See Also
StartSwitch
void UartPutc ( unsigned char  zeichen)

Send a single character to UART.

Parameters
zeichendata to send

Variable Documentation

volatile voidFuncPtr AdcIntFunc
volatile unsigned int adcValue[]
volatile int autoencode
volatile unsigned char count36kHz
volatile int encoder[2]

odometry sensors tick count access: encoder[LEFT], encoder[RIGHT]
range: 0..255

See Also
EncoderInit
volatile voidFuncPtr Ovr2IntFunc
volatile int switched

any switch pressed?

is being set to TRUE by interrupt if a switch is pressed
remember to set it to false again, since it is not reset automatically

See Also
StartSwitch
volatile unsigned long timebase
const char version[5]

Asuro Lib Versions String