kmot.c File Reference

This module provides useful basic facilities to use a KoreMotor. More...

Include dependency graph for kmot.c:

Go to the source code of this file.

Functions

void kmot_GetFWVersion (knet_dev_t *dev, unsigned int *version)
void kmot_GetStatus (knet_dev_t *dev, unsigned char *status, unsigned char *error)
void kmot_GetSpeedMultiplier (knet_dev_t *dev, unsigned short *mult)
void kmot_GetOptions (knet_dev_t *dev, unsigned char *software, unsigned char *hardware)
void kmot_ConfigurePID (knet_dev_t *dev, int regtype, int16_t Kp, int16_t Kd, int16_t Ki)
void kmot_SetPointSource (knet_dev_t *dev, int regtype, int wavetype, int period, int amplitude, int offset)
long kmot_GetMeasure (knet_dev_t *dev, int regtype)
void kmot_SetPosition (knet_dev_t *dev, long position)
void kmot_SetSpeedProfile (knet_dev_t *dev, int maxspeed, int acceleration)
void kmot_SetMinSpeed (knet_dev_t *dev, int minspeed)
void kmot_SetLimits (knet_dev_t *dev, int regtype, long softStopMin, long softStopMax)
int kmot_SearchLimits (knet_dev_t *dev, int8_t blockedTime, int32_t setPoint, int32_t *minpos, int32_t *maxpos, unsigned int timeout)
void kmot_SetOptions (knet_dev_t *dev, int hwOptions, int swOptions)
void kmot_SetPoint (knet_dev_t *dev, int regtype, long setPoint)
void kmot_SaveConfig (knet_dev_t *dev)
void kmot_ResetError (knet_dev_t *dev)
void kmot_SetBlockedTime (knet_dev_t *dev, int time)
void kmot_SetSampleTime (knet_dev_t *dev, int sample)
void kmot_SetFilterOrder (knet_dev_t *dev, int order)
void kmot_SetMode (knet_dev_t *dev, int mode)
void kmot_SetPrescale (knet_dev_t *dev, int mode)
void kmot_SetSpeedMultiplier (knet_dev_t *dev, int mode)
void kmot_SetVelocityPrescale (knet_dev_t *dev, int mode)
void kmot_SetMargin (knet_dev_t *dev, int margin)


Detailed Description

This module provides useful basic facilities to use a KoreMotor.

Support for the KoreMotor board.

Author:
Alexandre Colot (K-Team SA)

Pierre Bureau (K-Team SA)

Yves Piguet (Calerga)

CÚdric Gaudin (K-Team SA)

Note:
Copyright (C) 2004 K-TEAM SA
Bug:
none discovered.
Todo:
nothing.

Definition in file kmot.c.


Function Documentation

void kmot_ConfigurePID ( knet_dev_t dev,
int  regtype,
int16_t  Kp,
int16_t  Kd,
int16_t  Ki 
)

This function configures the PID controller using a given regulation mode. Please refer to the kMotRegType Definition

Parameters:
dev K-Net Device Descriptor
regtype Type of regulation
Kp PID Proportional Constant
Kd PID Differential Constant
Ki PID Integral Constant

Definition at line 241 of file kmot.c.

References KMOT_ORDER_MASK, kMotRegPos, kMotRegPosProfile, kMotRegSpeed, kMotRegSpeedProfile, kMotRegTorque, knet_set_order(), knet_write16(), MOT_KdPosL, MOT_KdSpeedL, MOT_KdTorqueL, MOT_KiPosL, MOT_KiSpeedL, MOT_KiTorqueL, MOT_KpPosL, MOT_KpSpeedL, and MOT_KpTorqueL.

Referenced by init(), initMot(), InitMotor(), kmot_ipConfigPID(), kmot_ipInitMotor(), main(), and setpid().

Here is the call graph for this function:

void kmot_GetFWVersion ( knet_dev_t dev,
unsigned int *  version 
)

This function get the firmware version and revision number.

Parameters:
dev K-Net Device Descriptor to the corresponding motor
version A pointer to a variable that will receive the firmware version number.

Definition at line 102 of file kmot.c.

References knet_read8(), and MOT_FWVersion.

Referenced by kmot_ipFirmware(), main(), and revisionOS().

Here is the call graph for this function:

long kmot_GetMeasure ( knet_dev_t dev,
int  regtype 
)

This function read a measure from a given motor.

Parameters:
dev K-Net Device Descriptor
regtype Type of regulation
Returns:
the measured position or torque depending on the type of regulation

Definition at line 316 of file kmot.c.

References KMOT_ORDER_MASK, kMotRegOpenLoop, kMotRegPos, kMotRegPosProfile, kMotRegSpeed, kMotRegSpeedProfile, kMotRegTorque, knet_read16(), knet_read32(), knet_set_order(), MOT_PositionLL, MOT_SpeedLL, and MOT_TorqueL.

Referenced by braitenbergAvoidance(), kmot_ipMeasure(), kmot_log_task(), left(), main(), measure(), right(), and test().

Here is the call graph for this function:

void kmot_GetOptions ( knet_dev_t dev,
unsigned char *  software,
unsigned char *  hardware 
)

This function gets the software options and hardware options.

Parameters:
dev K-Net Device Descriptor
software Software Options
hardware Hardware Options
Software Options:

  • bit 0 : Use alternate algorithm PID derivation. The derivate part is calculated using the process variable rather than the error
  • bit 1 : Activate the anti reset windup routine
  • bit 2 : Stop the motor if the min position is reached
  • bit 3 : Stop the motor if the max position is reached
  • bit 4 : Generate an error when position is out of limits, in this case the error must be re- seted before any further commands can be executed.
  • bit 5 : Stop the motor if the blocked condition is met
  • bit 6 : Activate software current limitation (Not implemented)
  • bit 7 : Invert the motor direction

Hardware Options:

  • bit 0 : Startup mode (0 = idle mode, 1 = control mode)
  • bit 1 : Use analog input for setpoint (Not Implemented)
  • bit 2 : Not Implemented
  • bit 3 : Resolution for the encoder (0 = 100%, 1 = 25%)
  • bit 4 : Invert the internal current measurement
  • bit 5 : Not Implemented
  • bit 6 : Not Implemented
  • bit 7 : Not Implemented

Definition at line 218 of file kmot.c.

References knet_read8(), MOT_HWOptions, and MOT_SWOptions.

Referenced by option().

Here is the call graph for this function:

void kmot_GetSpeedMultiplier ( knet_dev_t dev,
unsigned short *  mult 
)

This function gets the pid speed multiplier.

Definition at line 158 of file kmot.c.

References knet_read8(), MOT_SpeedMultH, and MOT_SpeedMultL.

Referenced by multiplier().

Here is the call graph for this function:

void kmot_GetStatus ( knet_dev_t dev,
unsigned char *  status,
unsigned char *  error 
)

This function gets the status flags and error flags.

Parameters:
dev K-Net Device Descriptor
status Status Flags
error Error Flags
Error Flags:

  • bit 0 : Sample time too small
  • bit 1 : Watchdog timer overflow
  • bit 2 : Brown-out
  • bit 3 : Software stoped motor (if softstop enabled)
  • bit 4 : Motor blocked (if motorblock enabled)
  • bit 5 : Position out of range
  • bit 6 : Speed out of range
  • bit 7 : Torque out of range

Status flags:

  • bit 0 : Movement detected
  • bit 1 : Direction 0=negative 1=positive
  • bit 2 : On setpoint
  • bit 3 : Near setpoint
  • bit 4 : Command saturated
  • bit 5 : Antireset windup active
  • bit 6 : Software current control active
  • bit 7 : Softstop active

Definition at line 141 of file kmot.c.

References knet_read8(), MOT_ErrorFlags, and MOT_StatusFlags.

Referenced by kmot_ipStatus(), main(), and status().

Here is the call graph for this function:

void kmot_ResetError ( knet_dev_t dev  ) 

This function resets the error register for the given motor, all controls are disabled while any error is active.

Parameters:
dev K-Net Device Descriptor corresponding to the motor

Definition at line 623 of file kmot.c.

References knet_write8(), and MOT_ErrorFlags.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), kmot_ipResetError(), koa_init_task(), main(), and statusclear().

Here is the call graph for this function:

void kmot_SaveConfig ( knet_dev_t dev  ) 

This function saves the current configuration for the given motor to the controller EEPROM. This EEPROM keeps the configuration even if the controller is switch off.

Parameters:
dev K-Net Device Descriptor corresponding to the motor

Definition at line 609 of file kmot.c.

References kMotModeSaveE2PROM, knet_write8(), and MOT_Mode.

Here is the call graph for this function:

int kmot_SearchLimits ( knet_dev_t dev,
int8_t  blockedTime,
int32_t  setPoint,
int32_t *  minpos,
int32_t *  maxpos,
unsigned int  timeout 
)

This function searches the system mechanical limits.

The blocked time can adjust the test sensitivity and the current limit used for blocked detection is the one set with kmot_SetLimits. The given speed is used to perform the test. The min and max positions are retruned with the minpos and maxpos parameters. The speed regulator must be properly configured before calling the search limit routine. This function is blocking and will not return until the search cycle is completed or until the number of given retry has been reached.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
blockedTime 
setPoint 
minpos Minimal mechanical position
maxpos Maximal mechanical position
timeout Timeout value in milli-seconds
Returns:
A value:
  • -1 on timeout
  • 0 on success

Definition at line 474 of file kmot.c.

References kb_getTime(), KMOT_ORDER_MASK, kMotModeSearchLimit, knet_read(), knet_read32(), knet_set_order(), knet_write32(), knet_write8(), MOT_BlockedTime, MOT_ControlTyp, MOT_Mode, MOT_SetPointLL, MOT_SoftStopMaxLL, and MOT_SoftStopMinLL.

Referenced by koa_init_task(), and main().

Here is the call graph for this function:

void kmot_SetBlockedTime ( knet_dev_t dev,
int  time 
)

kmot_SetBlockedTime -

Parameters:
dev K-Net Device Descriptor corresponding to the motor
time 

Definition at line 635 of file kmot.c.

References knet_write8(), and MOT_BlockedTime.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), koa_init_task(), and main().

Here is the call graph for this function:

void kmot_SetFilterOrder ( knet_dev_t dev,
int  order 
)

kmot_SetFilterOrder -

Parameters:
dev KNet Device Descriptor corresponding to the motor e
order didastelmotor_getVersion( 1 , &version );

Definition at line 662 of file kmot.c.

References knet_write8(), and MOT_Filter.

Here is the call graph for this function:

void kmot_SetLimits ( knet_dev_t dev,
int  regtype,
long  softStopMin,
long  softStopMax 
)

This function sets the limits for the given regulation.

The exact behavior when a measure reaches a limit depends on the controller options.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
regtype Type of regulation
softStopMin Minimal Software Stop Value
softStopMax Maximal Software Stop Value

Definition at line 424 of file kmot.c.

References KMOT_ORDER_MASK, kMotRegPos, kMotRegPosProfile, kMotRegTorque, knet_set_order(), knet_write16(), knet_write32(), MOT_SoftStopMaxLL, MOT_SoftStopMinLL, and MOT_SWCurrentLimitL.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), and main().

Here is the call graph for this function:

void kmot_SetMargin ( knet_dev_t dev,
int  margin 
)

kmot_SetMargin -

Parameters:
dev KNet Device Descriptor corresponding to the motor
margin 

Definition at line 742 of file kmot.c.

References knet_write8(), and MOT_NearTargetMargin.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), and main().

Here is the call graph for this function:

void kmot_SetMinSpeed ( knet_dev_t dev,
int  minspeed 
)

This function sets the minimum speed for the tapezoidal profile

The trapezoidal speed profile start with this minimal value to avoid a too low speed value that the PID won't be able to regulate.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
minspeed Minimal speed to start the trapeze

Definition at line 402 of file kmot.c.

References KMOT_ORDER_MASK, knet_set_order(), knet_write16(), and MOT_MinSpeedL.

Here is the call graph for this function:

void kmot_SetMode ( knet_dev_t dev,
int  mode 
)

kmot_SetMode -

Parameters:
dev KNet Device Descriptor corresponding to the motor
mode 

Definition at line 674 of file kmot.c.

References knet_write8(), and MOT_Mode.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), left(), left2(), left3(), main(), motStop(), right(), right2(), right3(), and stop().

Here is the call graph for this function:

void kmot_SetOptions ( knet_dev_t dev,
int  hwOptions,
int  swOptions 
)

This function sets the options for the given controller. Each SW and HW option parameters is a OR field of option flags.

Parameters:
dev K-Net Device Descriptor to the corresponding motor
hwOptions Hardware Option Flags
swOptions Software Option Flags
Software Option Flags:

  • kMotSWOptSepD : use alternate algorithm PID derivation
  • kMotSWOptWindup : activate the anti reset windup routine
  • kMotSWOptSoftStopMin : stop the motor if the min position is reached
  • kMotSWOptSoftStopMax : stop the motor if the max position is reached
  • kMotSwOptStopErr : generate an error when position is out of limits in this case the error must be rested before any further commands can be executed
  • kMotSWOptStopMotorBlk : stop the motor if the blocked condition is met (No movement, and current over the limit for the blocked time period).
  • kMotSWOptCurrentCtrl : activate software current limitation (Not implemented)
  • kMotSWOptDirectionInv : invert the motor direction

Hardware Option Flags:

  • kMotHWOptIdle : Idle Startup Mode
  • kMotHWOptNormal : Normal Control Startup Mode
  • kMotHWOptAnSetPtInEn : use analog input for setpoint (Not Implemented)
  • kMotHWOptLed : Not Implemented
  • kMotHWOptEncRes4x : 4x 100% resolution for the encoder
  • kMotHWOptEncRes1x : 1x 25% resolution for the encoder
  • kMotHWOptTorqueInv : invert the internal current measurement
  • kMotHWOptDriverOpt1 : Not Implemented
  • kMotHWOptDriverOpt2 : Not Implemented
  • kMotHWOptDriverOpt3 : Not Implemented

Definition at line 555 of file kmot.c.

References knet_write8(), MOT_HWOptions, and MOT_SWOptions.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), main(), and setoption().

Here is the call graph for this function:

void kmot_SetPoint ( knet_dev_t dev,
int  regtype,
long  setPoint 
)

This function sets a given target point for a given motor.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
regtype Type of regulation
setPoint 

Definition at line 569 of file kmot.c.

References KMOT_ORDER_MASK, kMotModeNormal, kMotPtSrcExtI2C, knet_read(), knet_set_order(), knet_write32(), knet_write8(), MOT_ControlTyp, MOT_Mode, MOT_SetPointLL, and MOT_SetPointSource.

Referenced by braitenbergAvoidance(), kmot_ipSetPos(), kmot_ipSetSpeed(), koa_net_bothcam(), koa_net_camera(), koa_net_camera2(), left(), left2(), left3(), main(), motMove(), motSpeed(), moveat(), moveatprofile(), openloop(), right(), right2(), right3(), setspeed(), setspeedprofile(), settorque(), and test().

Here is the call graph for this function:

void kmot_SetPointSource ( knet_dev_t dev,
int  regtype,
int  wavetype,
int  period,
int  amplitude,
int  offset 
)

This function selects a source for the target point. Usually the setpoint is given by the application with knet commnands, on some cases, an internal signal generator can provide a variable setpoint.

Parameters:
dev K-Net Device Descriptor
regtype Type of regluation. See kMotRegType
wavetype Target Point Source. See kMotPointSource
period Period [0..255]
amplitude Amplitude [0..255]
offset Offset [-128..127]

Definition at line 292 of file kmot.c.

References knet_write8(), MOT_ControlTyp, MOT_IntGenAmplitude, MOT_IntGenOffset, MOT_IntGenPeriod, MOT_Mode, and MOT_SetPointSource.

Referenced by kmot_ipSetPointSource().

Here is the call graph for this function:

void kmot_SetPosition ( knet_dev_t dev,
long  position 
)

This function sets the position counter to the given value for a given motor.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
position New position value

Definition at line 365 of file kmot.c.

References KMOT_ORDER_MASK, knet_set_order(), knet_write32(), and MOT_PositionLL.

Referenced by setpos().

Here is the call graph for this function:

void kmot_SetPrescale ( knet_dev_t dev,
int  mode 
)

kmot_SetPrescale -

Parameters:
dev KNet Device Descriptor corresponding to the motor
prescale 

Definition at line 687 of file kmot.c.

References knet_write8(), and MOT_Prescale.

Referenced by prescaler().

Here is the call graph for this function:

void kmot_SetSampleTime ( knet_dev_t dev,
int  sample 
)

kmot_SetSampleTime -

Parameters:
dev K-Net Device Descriptor corresponding to the motor
sample 

Definition at line 647 of file kmot.c.

References KMOT_ORDER_MASK, knet_set_order(), knet_write8(), MOT_SampleTimeH, and MOT_SampleTimeL.

Referenced by init(), initMot(), InitMotor(), kmot_ipInitMotor(), main(), and setsampletime().

Here is the call graph for this function:

void kmot_SetSpeedMultiplier ( knet_dev_t dev,
int  mode 
)

kmot_SetSpeedMultiplier -

Parameters:
dev KNet Device Descriptor corresponding to the motor
prescale 

Definition at line 700 of file kmot.c.

References knet_write8(), MOT_SpeedMultH, and MOT_SpeedMultL.

Referenced by setmultiplier().

Here is the call graph for this function:

void kmot_SetSpeedProfile ( knet_dev_t dev,
int  maxspeed,
int  acceleration 
)

This function sets the profile for position regulation.

The trapezoidal speed profile is calculated using the acceleration until the maxspeed is reached. -acceleration is used to decelerate until target position is reached.

Parameters:
dev K-Net Device Descriptor corresponding to the motor
maxspeed Maximal speed to reach
acceleration Acceleration

Definition at line 383 of file kmot.c.

References KMOT_ORDER_MASK, knet_set_order(), knet_write16(), knet_write8(), MOT_Acceleration, and MOT_MaxSpeedL.

Referenced by configspeedprofile(), init(), initMot(), InitMotor(), kmot_ipInitMotor(), and main().

Here is the call graph for this function:

void kmot_SetVelocityPrescale ( knet_dev_t dev,
int  mode 
)

kmot_SetVelocityPrescale -

Parameters:
dev KNet Device Descriptor corresponding to the motor
prescale 

Definition at line 730 of file kmot.c.

References knet_write8(), and MOT_VelocityPrescaler.

Referenced by velprescaler().

Here is the call graph for this function:


Generated on Wed Dec 15 11:49:29 2010 for KoreBot Library by  doxygen 1.5.5