kh3server.c File Reference

This is application waits for Khepera 3 commands A-Z received from serial port usage: kh3server [serial_port (optional)]. More...

Include dependency graph for kh3server.c:

Go to the source code of this file.

Defines

#define MAXBUFFERSIZE   128
#define BAUDRATE   B115200
#define VAL_BAUDRATE   115200
#define SERIAL_PORT   "/dev/ttyS1"
#define ERROR_CMD_CHAR   '$'
#define MAX_ARG   4
#define ARG_LENGTH   10
#define BR_IRGAIN   30
#define fwSpeed   20
#define MIN_SPEED   10
#define RotSpeedL   50
#define RotSpeedR   -50
#define RS232_EOA   ','
#define EOL_TEST(data)   (data == '\r' || data == '\n' || data == '\0')

Typedefs

typedef char string [ARG_LENGTH]

Enumerations

enum  { Timeout = 800, LineLength = 16 + 64 + 1 + 1 + 1 }

Functions

int process_command ()
static void ctrlc_handler (int sig)
int kbhit (void)
void clear_screen ()
static int com_connect (const char *device, speed_t baudrate)
static int com_send (const char *data, int size)
static int com_recv (char *data, int max_size, int timeout)
static int readLine (char *buffer)
int initMot (knet_dev_t *hDev)
int initKH3 (void)
int InitMot (int narg, string *larg)
int ReadProxSensors (int narg, string *larg)
int ReadAmbSensors (int narg, string *larg)
int batStatus (int narg, string *larg)
int tstampRST (int narg, string *larg)
int revisionOS (int narg, string *larg)
int configureOS (int argc, string *argv)
int GetUS (int argc, string *argv)
int SetSpeed (int argc, string *argv)
int SetSpeedOpenLoop (int argc, string *argv)
int GetSpeed (int argc, string *argv)
int SetTargetProfile (int argc, string *argv)
int SetTargetPosition (int argc, string *argv)
int SetEncPosition (int argc, string *argv)
int ReadPos (int argc, string *argv)
int ConfigPID (int argc, string *argv)
int ConfigSpeedProfile (int argc, string *argv)
int SetLED (int argc, string *argv)
int braitenberg (int argc, string *argv)
int getArgs (char *buf, string *larg)
int BinaryRead (int narg, string *larg)
int main (int argc, char *argv[])

Variables

static int porthandle = -1
static int quitReq = 0
static char buf [1024]
static knet_dev_tdsPic
static knet_dev_tmot1
static knet_dev_tmot2

Detailed Description

This is application waits for Khepera 3 commands A-Z received from serial port usage: kh3server [serial_port (optional)].

Khepera3 server application

Author:
Julien Tharin (K-Team SA)
Note:
Copyright (C) 2012 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file kh3server.c.


Define Documentation

#define ARG_LENGTH   10

Definition at line 38 of file kh3server.c.

#define BAUDRATE   B115200

Definition at line 25 of file kh3server.c.

#define BR_IRGAIN   30

Braintenberg mode

Parameters:
argc number of argument
argv first param (argv[0]) is avoidance sensor 0 = IR, 1 = US (unimplemented)
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 1056 of file kh3server.c.

Referenced by braitenberg(), and braitenbergAvoidance().

#define EOL_TEST ( data   )     (data == '\r' || data == '\n' || data == '\0')

Definition at line 1245 of file kh3server.c.

#define ERROR_CMD_CHAR   '$'

Definition at line 34 of file kh3server.c.

Referenced by batStatus(), braitenberg(), and process_command().

#define fwSpeed   20

Definition at line 1057 of file kh3server.c.

Referenced by braitenberg(), and braitenbergAvoidance().

#define MAX_ARG   4

Definition at line 37 of file kh3server.c.

Referenced by getArgs(), and process_command().

#define MAXBUFFERSIZE   128
#define MIN_SPEED   10

Definition at line 1058 of file kh3server.c.

#define RotSpeedL   50

Definition at line 1059 of file kh3server.c.

Referenced by braitenberg(), and braitenbergAvoidance().

#define RotSpeedR   -50

Definition at line 1060 of file kh3server.c.

Referenced by braitenberg(), and braitenbergAvoidance().

#define RS232_EOA   ','

Definition at line 1244 of file kh3server.c.

Referenced by getArgs().

#define SERIAL_PORT   "/dev/ttyS1"

Definition at line 27 of file kh3server.c.

Referenced by main().

#define VAL_BAUDRATE   115200

Definition at line 26 of file kh3server.c.

Referenced by main().


Typedef Documentation

typedef char string[ARG_LENGTH]

Definition at line 39 of file kh3server.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
Timeout 
LineLength 

Definition at line 29 of file kh3server.c.


Function Documentation

int batStatus ( int  narg,
string larg 
)

batStatus retrieves the battery status using kb_khepera3.c library.

Parameters:
narg number of argument
larg state to inquire
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 489 of file kh3server.c.

References com_send(), ERROR_CMD_CHAR, kh3_battery_voltage(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int BinaryRead ( int  narg,
string larg 
)

BinaryRead for GUI

Parameters:
narg number of argument
larg array of argument
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 1296 of file kh3server.c.

References buf, com_send(), kh3_ambiant_ir(), kh3_proximity_ir(), kmot_GetMeasure(), kMotMesSpeed, kMotRegPos, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int braitenberg ( int  argc,
string argv 
)
void clear_screen (  ) 

clear screen

Returns:
none

Definition at line 113 of file kh3server.c.

static int com_connect ( const char *  device,
speed_t  baudrate 
) [static]

connect to serial port

Parameters:
device device name
baudrate baudrate
Returns:
>=0 : Ok; -1 : cannot open serial port

Definition at line 126 of file kh3server.c.

References HComm.

Referenced by main().

static int com_recv ( char *  data,
int  max_size,
int  timeout 
) [static]

receive data from serial port

Parameters:
data data to be sent to the port
max_size max size of the data variable
timeout timeout in [ms]
Returns:
number of data read

Definition at line 193 of file kh3server.c.

References porthandle.

static int com_send ( const char *  data,
int  size 
) [static]

write to serial port

Parameters:
data data to be sent to the port
size size of the data
Returns:
number of written char

Definition at line 173 of file kh3server.c.

References porthandle.

Referenced by batStatus(), BinaryRead(), braitenberg(), ConfigPID(), ConfigSpeedProfile(), configureOS(), GetSpeed(), GetUS(), InitMot(), process_command(), ReadAmbSensors(), ReadPos(), ReadProxSensors(), revisionOS(), SetEncPosition(), SetLED(), SetSpeed(), SetSpeedOpenLoop(), SetTargetPosition(), SetTargetProfile(), and tstampRST().

int ConfigPID ( int  argc,
string argv 
)

Configure PID

Parameters:
argc number of argument
argv first param (argv[0]) is 0 speed control or 1 position control second param (argv[1]) is the Kp parameter third param (argv[2]) is the Ki parameter forth param (argv[3]) is the Kd parameter
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 938 of file kh3server.c.

References com_send(), kmot_ConfigurePID(), kMotRegPos, kMotRegSpeed, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int ConfigSpeedProfile ( int  argc,
string argv 
)

configure speed and acceleration profiles

Parameters:
argc number of argument
argv array of argument
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 981 of file kh3server.c.

References com_send(), kmot_SetSpeedProfile(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int configureOS ( int  argc,
string argv 
)

configureOS configures various parameters inside the kh3 firmware using kb_khepera3.c library.

Parameters:
argc number of argument
argv first param (argv[1]) is the index pointing in configuration array. 2nd the second param (argv[2]) is the value to store where the index point at.

Definition at line 613 of file kh3server.c.

References com_send(), kh3_configure_os(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

static void ctrlc_handler ( int  sig  )  [static]

Intercept the ctrl-c

Parameters:
sig signal
Returns:
none

Definition at line 64 of file kh3server.c.

References quitReq.

int getArgs ( char *  buf,
string larg 
)

getArgs separate argument , return arguments number and save in larg every argument

Parameters:
buf arguments string
larg array of argument
Returns:
arguments number

Definition at line 1255 of file kh3server.c.

References MAX_ARG, and RS232_EOA.

Referenced by process_command().

int GetSpeed ( int  argc,
string argv 
)

Getspeed

Parameters:
argc number of argument
argv array of argument
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 757 of file kh3server.c.

References com_send(), kmot_GetMeasure(), kMotMesSpeed, left, MAXBUFFERSIZE, and right.

Referenced by process_command().

Here is the call graph for this function:

int GetUS ( int  argc,
string argv 
)

measureUS retrieves ultrasonic measure from a given transceiver.

Parameters:
argc number of argument
argv first param (argv[0]) is the us number to read from (1 to 5).
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 649 of file kh3server.c.

References buf, com_send(), kh3_measure_us(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int initKH3 ( void   ) 

initKH3 initialize various things in the kh3 then sequentialy open the various required handle to the three i2c devices on the khepera3 using knet_open from the knet.c libkorebot's modules. Finaly, this function initializes then configures the motor control unit.

Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 342 of file kh3server.c.

References initMot(), kh3_init(), KNET_BUS_I2C, and knet_open().

Here is the call graph for this function:

int InitMot ( int  narg,
string larg 
)

Init mot or reset motor controller

Parameters:
narg number of argument
larg argument array
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 378 of file kh3server.c.

References com_send(), initMot(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int initMot ( knet_dev_t hDev  ) 

initMot initializes then configures the motor control unit.

Parameters:
hDev device handle
Returns:
A value :
  • 1 if success
  • 0 if any error

Definition at line 300 of file kh3server.c.

References kmot_ConfigurePID(), kmot_ResetError(), kmot_SetBlockedTime(), kmot_SetLimits(), kmot_SetMargin(), kmot_SetMode(), kmot_SetOptions(), kmot_SetSampleTime(), kmot_SetSpeedProfile(), kMotModeIdle, kMotRegCurrent, kMotRegPos, kMotRegSpeed, kMotSWOptDirectionInv, kMotSWOptStopMotorBlk, and kMotSWOptWindup.

Here is the call graph for this function:

int kbhit ( void   ) 

Kbhit helper function

Returns:
A value :
  • 1 Character pending
  • 0 no character
    • -1 error

Definition at line 79 of file kh3server.c.

int main ( int  argc,
char *  argv[] 
)

Definition at line 1481 of file kh3server.c.

References BAUDRATE, com_connect(), initKH3(), kh3_revision(), MAXBUFFERSIZE, porthandle, process_command(), quitReq, SERIAL_PORT, and VAL_BAUDRATE.

Here is the call graph for this function:

int process_command (  ) 

process command

Returns:
A value : braitenberg end mode
  • 0 if success
  • <0 if any error

Definition at line 1379 of file kh3server.c.

References batStatus(), BinaryRead(), braitenberg(), com_send(), ConfigPID(), ConfigSpeedProfile(), configureOS(), ERROR_CMD_CHAR, getArgs(), GetSpeed(), GetUS(), InitMot(), MAX_ARG, MAXBUFFERSIZE, ReadAmbSensors(), readLine(), ReadPos(), ReadProxSensors(), revisionOS(), SetEncPosition(), SetLED(), SetSpeed(), SetSpeedOpenLoop(), SetTargetPosition(), SetTargetProfile(), and tstampRST().

Referenced by braitenberg(), and main().

Here is the call graph for this function:

int ReadAmbSensors ( int  narg,
string larg 
)

ambIR retrieves ambiant ir measure using kb_khepera3.c library.

Parameters:
narg number of argument
larg argument array
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 449 of file kh3server.c.

References com_send(), kh3_ambiant_ir(), MAXBUFFERSIZE, and sensor().

Referenced by process_command().

Here is the call graph for this function:

static int readLine ( char *  buffer  )  [static]

Definition at line 266 of file kh3server.c.

Referenced by process_command().

int ReadPos ( int  argc,
string argv 
)

GetMotPos get the motor position.

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 position. second param (argv[1]) is the motor2 position.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 897 of file kh3server.c.

References com_send(), kmot_GetMeasure(), kMotMesPos, left, MAXBUFFERSIZE, and right.

Referenced by process_command().

Here is the call graph for this function:

int ReadProxSensors ( int  narg,
string larg 
)

proxIR retrieves proximity ir measure using kb_khepera3.c library.

Parameters:
narg number of argument
larg argument array
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 409 of file kh3server.c.

References com_send(), kh3_proximity_ir(), MAXBUFFERSIZE, and sensor().

Referenced by process_command().

Here is the call graph for this function:

int revisionOS ( int  narg,
string larg 
)

revisionOS retrieves the khepera3 os version using kb_khepera3.c library.

Parameters:
narg number of argument
larg array of argument
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 587 of file kh3server.c.

References com_send(), kh3_revision(), and MAXBUFFERSIZE.

Here is the call graph for this function:

int SetEncPosition ( int  argc,
string argv 
)

SetEncPosition set encoder position

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 position. second param (argv[1]) is the motor2 position.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 861 of file kh3server.c.

References com_send(), kmot_SetPosition(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int SetLED ( int  argc,
string argv 
)

set led

Parameters:
argc number of argument
argv first param (argv[0]) is led index second param (argv[1]) is led state to set
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 1012 of file kh3server.c.

References buf, com_send(), kh3_getcommand(), kh3_sendcommand(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int SetSpeed ( int  argc,
string argv 
)

SetSpeed configures the motor controller speed in the engine control unit.

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 speed. 2nd second param (argv[1]) is the motor2 speed.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 687 of file kh3server.c.

References com_send(), kmot_SetPoint(), kMotRegSpeed, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int SetSpeedOpenLoop ( int  argc,
string argv 
)

SetSpeedOpenLoop configures the motor controller speed in the engine control unit.

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 speed. 2nd second param (argv[1]) is the motor2 speed.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 724 of file kh3server.c.

References com_send(), kmot_SetPoint(), kMotRegOpenLoop, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int SetTargetPosition ( int  argc,
string argv 
)

SetTargetPosition move without the acceleration and decceleration.

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 position. second param (argv[1]) is the motor2 position.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 826 of file kh3server.c.

References com_send(), kmot_SetPoint(), kMotRegPos, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int SetTargetProfile ( int  argc,
string argv 
)

SetTargetProfile configures the motor controller position in the engine control unit using the PID and speed/accel profile.

Parameters:
argc number of argument
argv first param (argv[0]) is the motor1 position. second param (argv[1]) is the motor2 position.
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 795 of file kh3server.c.

References com_send(), kmot_SetPoint(), kMotRegPosProfile, and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:

int tstampRST ( int  narg,
string larg 
)

tstampRST resets the relative time stamp using kb_khepera3.c library.

Parameters:
narg number of argument
larg array of argument
Returns:
A value :
  • 0 if success
  • <0 if any error

Definition at line 562 of file kh3server.c.

References com_send(), kh3_reset_tstamp(), and MAXBUFFERSIZE.

Referenced by process_command().

Here is the call graph for this function:


Variable Documentation

char buf[1024] [static]

Definition at line 44 of file kh3server.c.

Referenced by BinaryRead(), braitenberg(), GetUS(), and SetLED().

knet_dev_t* dsPic [static]

handle to the various khepera3 devices (knet socket, i2c mode)

Definition at line 49 of file kh3server.c.

knet_dev_t* mot1 [static]

Definition at line 50 of file kh3server.c.

knet_dev_t* mot2 [static]

Definition at line 51 of file kh3server.c.

int porthandle = -1 [static]

Definition at line 41 of file kh3server.c.

Referenced by braitenberg(), com_recv(), com_send(), and main().

int quitReq = 0 [static]

Definition at line 43 of file kh3server.c.

Referenced by ctrlc_handler(), and main().

Generated on Mon Dec 3 09:43:49 2012 for KoreBot Library by  doxygen 1.6.3