kh3moves.c File Reference

This file implements many different movement commands which can be issued to the robot. More...

#include "kh3moves.h"
#include "guardmodes.h"
#include <korebot/korebot.h>
#include <math.h>
#include <stdio.h>
#include <unistd.h>

Include dependency graph for kh3moves.c:

Go to the source code of this file.

Defines

#define WHEELCIRCUM   132.3
 Khepera's wheel circumference in [mm].
#define F_OSC   5000000
 20MHz/4
#define POSTSCALER   4
 Motor pulse counter scaler (default value).
#define PULSESPERREV   2764.0
 Motor pulses per complete revolution.
#define TMR5PRESCALER   8
 Default prescaler value (default value).
#define KMOT_MIN_SPEED   2000
 Kheperas minimal motor speed.
#define KMOT_MAX_SPEED   43000
 Kheperas maximal motor speed.
#define LEFTARC   0
 Types of walk arcs - this is a left arc.
#define RIGHTARC   1
 Types of walk arcs - this is a right arc.

Functions

int kh3_mm2pulse (double dist)
 converts distance in millimeters to Khepera's pulses
void kh3_showMaskMsg (const unsigned char value, const unsigned char mask, const char *success, const char *failure)
 Shows a message, if a all bits given in the mask are set.
int motInfo (knet_dev_t *mot)
 Show numerous information about the given motor.
void kmot_SetDefaultSpeedProfile (knet_dev_t *mot)
 Sets the default speed profile we like.
int kh3_initMot (knet_dev_t *mot)
 Inits a motor by setting some default values.
int kh3_initRobot (void)
 Initialize the robot.
int kh3_motInfo (int showLeftMot, int showRightMot)
 Print information about left or right motor.
int kh3_moveRelative (int left, int right)
 Moves both wheels relative to the current position.
int kh3_forw (double left, double right)
 Move the robot forward.
int kh3_back (double left, double right)
 Move the robot backward.
int kh3_stop (void)
 Stop the motors.
int kh3_reset (void)
 Resets both motors (initializes them).
int kh3_speed (double lSpeed, double rSpeed)
 Set constant speed for motors.
int kh3_sideAwareSpeed (double innerSpeed, double outerSpeed, char guardSide)
 Sets the speed for the inner and outer wheel, according to the side the robot is following.
int kh3_left (double angle)
 Turn robot to the left, around its centre.
int kh3_right (double angle)
 Turn robot to the right, around its centre.
int kh3_sideAwareRotate (double angle, char guardSide)
 Rotatates the robot towards or away from the wall.
int kh3_goOnArc (double angle, int side, double center)
 Let's the Khepera robot walk on an arc.
int kh3_arcLeft (double angle, double center)
 Let the robot walk on a left arc.
int kh3_arcRight (double angle, double center)
 Let the robot walk on a right arc.
int kh3_isMoving (void)
 Tells if the robot is currently moving.

Variables

knet_dev_t * dsPic = NULL
 Khepera's status information device.
knet_dev_t * lMot = NULL
 Khepera's left motor.
knet_dev_t * rMot = NULL
 Khepera's right motor.
const double kSpeed = ( 0xFFFFFF / ( (WHEELCIRCUM * F_OSC * 4) / (PULSESPERREV * 8) ) )
 Translation factor from mm/s to Khepera's internal speed.


Detailed Description

This file implements many different movement commands which can be issued to the robot.

Version:
Id
kh3moves.c,v 1.14 2008/09/18 12:59:02 prokop Exp

Definition in file kh3moves.c.


Define Documentation

#define F_OSC   5000000

20MHz/4

Definition at line 37 of file kh3moves.c.

#define KMOT_MAX_SPEED   43000

Kheperas maximal motor speed.

Definition at line 47 of file kh3moves.c.

#define KMOT_MIN_SPEED   2000

Kheperas minimal motor speed.

Definition at line 45 of file kh3moves.c.

#define LEFTARC   0

Types of walk arcs - this is a left arc.

Definition at line 52 of file kh3moves.c.

#define POSTSCALER   4

Motor pulse counter scaler (default value).

Definition at line 39 of file kh3moves.c.

#define PULSESPERREV   2764.0

Motor pulses per complete revolution.

Definition at line 41 of file kh3moves.c.

#define RIGHTARC   1

Types of walk arcs - this is a right arc.

Definition at line 54 of file kh3moves.c.

#define TMR5PRESCALER   8

Default prescaler value (default value).

Definition at line 43 of file kh3moves.c.

#define WHEELCIRCUM   132.3

Khepera's wheel circumference in [mm].

Definition at line 35 of file kh3moves.c.


Function Documentation

int kh3_arcLeft ( double  angle,
double  center 
)

Let the robot walk on a left arc.

Parameters:
angle rotation (walk) angle in degrees
center distance from robot's centre to the arc's centre
Returns:
0 on success, -1 on failure

Definition at line 480 of file kh3moves.c.

int kh3_arcRight ( double  angle,
double  center 
)

Let the robot walk on a right arc.

Parameters:
angle rotation (walk) angle in degrees
center distance from robot's centre to the arc's centre
Returns:
0 on success, -1 on failure

Definition at line 484 of file kh3moves.c.

int kh3_back ( double  left,
double  right 
)

Move the robot backward.

positions can be negative, in which case this function would be identical to "kh3_forw".

Parameters:
left Distance for the left motor in [mm]
right Distance for the right motor in [mm]
Returns:
0 on success, -1 on failure

Definition at line 290 of file kh3moves.c.

int kh3_forw ( double  left,
double  right 
)

Move the robot forward.

Parameters:
left Distance for the left motor in [mm]
right Distance for the right motor in [mm]
Returns:
0 on success, -1 on failure
positions can be negative, in which case this function would be identical to "kh3_back".

Definition at line 286 of file kh3moves.c.

int kh3_goOnArc ( double  angle,
int  side,
double  center 
)

Let's the Khepera robot walk on an arc.

Parameters:
angle The angle in degrees which the robot should walk
side tells if it is a right or left arc walk (LEFTARC, RIGHTARC)
center Distance in [mm] from robot's centre to arc's centre
Returns:
0 on success, 1 on error

Definition at line 401 of file kh3moves.c.

int kh3_initMot ( knet_dev_t *  mot  ) 

Inits a motor by setting some default values.

Parameters:
mot Motor to initialize
Returns:
-1 on error, 0 on success

Definition at line 179 of file kh3moves.c.

int kh3_initRobot ( void   ) 

Initialize the robot.

This aquires the pointers to Khepera's PIC controllers motors, battery, sensors, etc.

Returns:
0 on success, -1 on init errors and -2 if Khepera's devices could not be found

Definition at line 224 of file kh3moves.c.

int kh3_isMoving ( void   ) 

Tells if the robot is currently moving.

Returns:
1 if the robots is moving, 0 if it stopped

Definition at line 488 of file kh3moves.c.

int kh3_left ( double  angle  ) 

Turn robot to the left, around its centre.

Parameters:
angle rotation angle in degrees
Returns:
0 on success, -1 on failure

Definition at line 362 of file kh3moves.c.

int kh3_mm2pulse ( double  dist  ) 

converts distance in millimeters to Khepera's pulses

Parameters:
dist distance in [mm]
Returns:
motor pulses corresponding to the distance This function is for internal use only.

Definition at line 67 of file kh3moves.c.

int kh3_motInfo ( int  showLeftMot,
int  showRightMot 
)

Print information about left or right motor.

Parameters:
showLeftMot show information about left motor (boolean)
showRightMot show information about right motor (boolean)
Returns:
1 on success, 0 on failure (e.g. uninitialized motor)

Definition at line 247 of file kh3moves.c.

int kh3_moveRelative ( int  left,
int  right 
)

Moves both wheels relative to the current position.

This is a helper function for almost every other move related function

Parameters:
left relative position for the left motor
right relative position for the right motor
Returns:
0 on success, -1 on failure

Definition at line 264 of file kh3moves.c.

int kh3_reset ( void   ) 

Resets both motors (initializes them).

Returns:
0 on success, -1 on failure

Definition at line 304 of file kh3moves.c.

int kh3_right ( double  angle  ) 

Turn robot to the right, around its centre.

Parameters:
angle rotation angle in degrees
Returns:
0 on success, -1 on failure

Definition at line 371 of file kh3moves.c.

void kh3_showMaskMsg ( const unsigned char  value,
const unsigned char  mask,
const char *  success,
const char *  failure 
)

Shows a message, if a all bits given in the mask are set.

Parameters:
value bit field in question
mask mask to apply to the bit field
success message which will be shown if the bit is set
failure message which will be shown if the bit is not set

Definition at line 71 of file kh3moves.c.

int kh3_sideAwareRotate ( double  angle,
char  guardSide 
)

Rotatates the robot towards or away from the wall.

Parameters:
angle The angle to go (in degrees). Positive values rotate the robot's front away from the wall, negative towards.
guardSide The side, one of GUARD_SIDE_LEFT or GUARD_SIDE_RIGHT
Returns:
0 on success or a negative value on failures

Definition at line 380 of file kh3moves.c.

int kh3_sideAwareSpeed ( double  innerSpeed,
double  outerSpeed,
char  guardSide 
) [inline]

Sets the speed for the inner and outer wheel, according to the side the robot is following.

Parameters:
innerSpeed speed for the inner wheel in [mm/s]
outerSpeed speed for the outer wheel in [mm/s]
guardSide guard's side, one of GUARD_SIDE_LEFT or GUARD_SIDE_RIGHT
Returns:
0 on success, a negative value on failure

Definition at line 348 of file kh3moves.c.

int kh3_speed ( double  lSpeed,
double  rSpeed 
)

Set constant speed for motors.

Parameters:
lSpeed Speed for the left motor [mm/s]
rSpeed Speed for the right motor [mm/s]
Returns:
0 on success, -1 on failure Speed is specified in millimeters pers second.

Definition at line 314 of file kh3moves.c.

int kh3_stop ( void   ) 

Stop the motors.

Returns:
0 on success, -1 on failure

Definition at line 294 of file kh3moves.c.

void kmot_SetDefaultSpeedProfile ( knet_dev_t *  mot  ) 

Sets the default speed profile we like.

Parameters:
mot motor for which the profile will be set

Definition at line 175 of file kh3moves.c.

int motInfo ( knet_dev_t *  mot  ) 

Show numerous information about the given motor.

Parameters:
mot Motor whose status we want
Returns:
1. Always.

Definition at line 89 of file kh3moves.c.


Variable Documentation

knet_dev_t* dsPic = NULL

Khepera's status information device.

Khepera status device.

Definition at line 58 of file kh3moves.c.

const double kSpeed = ( 0xFFFFFF / ( (WHEELCIRCUM * F_OSC * 4) / (PULSESPERREV * 8) ) )

Translation factor from mm/s to Khepera's internal speed.

Definition at line 65 of file kh3moves.c.

knet_dev_t* lMot = NULL

Khepera's left motor.

Definition at line 60 of file kh3moves.c.

knet_dev_t* rMot = NULL

Khepera's right motor.

Definition at line 62 of file kh3moves.c.


Generated on Sun Sep 28 21:20:01 2008 for Guard by  doxygen 1.5.6