SimpleFOClibrary  2.1
Commander Class Reference

#include <Commander.h>

Public Member Functions

 Commander (Stream &serial)
 
 Commander ()
 
void run ()
 
void run (Stream &reader)
 
void run (char *user_input)
 
void add (char id, CommandCallback onCommand, char *label=nullptr)
 
void motor (FOCMotor *motor, char *user_cmd)
 
void lpf (LowPassFilter *lpf, char *user_cmd)
 
void pid (PIDController *pid, char *user_cmd)
 
void scalar (float *value, char *user_cmd)
 

Public Attributes

VerboseMode verbose = VerboseMode::user_friendly
 flag signaling that the commands should output user understanable text More...
 
uint8_t decimal_places = 3
 number of decimal places to be used when displaying numbers More...
 
Stream * com_port = nullptr
 Serial terminal variable if provided. More...
 

Detailed Description

Commander class implementing string communication protocol based on IDvalue (ex AB5.321 - command id A, sub-command id B,value 5.321)

  • This class can be used in combination with HardwareSerial instance which it would read and write or it can be used to parse strings that have been received from the user outside this library
  • Commander class implements command protocol for few standard components of the SimpleFOC library
  • Commander also provides a very simple command > callback interface that enables user to attach a callback function to certain command id - see function add()

Definition at line 33 of file Commander.h.

Constructor & Destructor Documentation

◆ Commander() [1/2]

Commander::Commander ( Stream &  serial)

Default constructor receiving a serial interface that it uses to output the values to Also if the function run() is used it uses this serial instance to read the serial for user commands

Parameters
serial- Serial com port instance

Definition at line 4 of file Commander.cpp.

◆ Commander() [2/2]

Commander::Commander ( )

Definition at line 7 of file Commander.cpp.

Member Function Documentation

◆ add()

void Commander::add ( char  id,
CommandCallback  onCommand,
char *  label = nullptr 
)

Function adding a callback to the coomander withe the command id

Parameters
id- char command letter
onCommand- function pointer void function(char*)
label- string label to be displayed when scan command sent

Definition at line 12 of file Commander.cpp.

◆ lpf()

void Commander::lpf ( LowPassFilter lpf,
char *  user_cmd 
)

Low pass fileter command interface

  • It only has one property - filtering time constant Tf
  • It can be get by sending 'F'
  • It can be set by sending 'Fvalue' - (ex. F0.01 for settin Tf=0.01)

Definition at line 364 of file Commander.cpp.

◆ motor()

void Commander::motor ( FOCMotor motor,
char *  user_cmd 
)

FOC motor (StepperMotor and BLDCMotor) command interface

  • It has several paramters (the letters can be changed in the commands.h file) 'Q' - Q current PID controller & LPF (see function pid and lpf for commands) 'D' - D current PID controller & LPF (see function pid and lpf for commands)
    'V' - Velocity PID controller & LPF (see function pid and lpf for commands)
    'A' - Angle PID controller & LPF (see function pid and lpf for commands) 'L' - Limits
    sub-commands: 'C' - Current
    'U' - Voltage
    'V' - Velocity
    'C' - Motion control type config
    sub-commands: 'D' - downsample motiron loop '0' - torque
    '1' - velocity '2' - angle
    'T' - Torque control type
    sub-commands: '0' - voltage
    '1' - current
    '2' - foc_current 'E' - Motor status (enable/disable)
    sub-commands: '0' - enable
    '1' - disable
    'R' - Motor resistance
    'S' - Sensor offsets
    sub-commands: 'M' - sensor offset
    'E' - sensor electrical zero 'M' - Monitoring control
    sub-commands: 'D' - downsample monitoring
    'C' - clear monitor
    'S' - set monitoring variables
    'G' - get variable value
    '' - Target get/set
  • Each of them can be get by sening the command letter -(ex. 'R' - to get the phase resistance)
  • Each of them can be set by sending 'IdSubidValue' - (ex. SM1.5 for setting sensor zero offset to 1.5)

Definition at line 102 of file Commander.cpp.

◆ pid()

void Commander::pid ( PIDController pid,
char *  user_cmd 
)

PID controller command interface

  • It has several paramters (the letters can be changed in the commands.h file)
    • P gain - 'P'
    • I gain - 'I'
    • D gain - 'D'
    • output ramp - 'R'
    • output limit - 'L'
  • Each of them can be get by sening the command letter -(ex. 'D' - to get the D gain)
  • Each of them can be set by sending 'IDvalue' - (ex. I1.5 for setting I=1.5)

Definition at line 327 of file Commander.cpp.

◆ run() [1/3]

void Commander::run ( )

Function reading the serial port and firing callbacks that have been added to the commander once the user has requested them - when he sends the command

  • It has default commands (the letters can be changed in the commands.h file) '@' - Verbose mode
    '#' - Number of decimal places '?' - Scan command - displays all the labels of attached nodes

Definition at line 20 of file Commander.cpp.

◆ run() [2/3]

void Commander::run ( char *  user_input)

Function reading the string of user input and firing callbacks that have been added to the commander once the user has requested them - when he sends the command

  • It has default commands (the letters can be changed in the commands.h file) '@' - Verbose mode
    '#' - Number of decimal places '?' - Scan command - displays all the labels of attached nodes
Parameters
user_input- string of user inputs

Definition at line 61 of file Commander.cpp.

◆ run() [3/3]

void Commander::run ( Stream &  reader)

Function reading the string of user input and firing callbacks that have been added to the commander once the user has requested them - when he sends the command

  • It has default commands (the letters can be changed in the commands.h file) '@' - Verbose mode
    '#' - Number of decimal places '?' - Scan command - displays all the labels of attached nodes
Parameters
reader- Stream to read user input

Definition at line 38 of file Commander.cpp.

◆ scalar()

void Commander::scalar ( float *  value,
char *  user_cmd 
)

Float variable scalar command interface

  • It only has one property - one float value
  • It can be get by sending an empty string '
    '
  • It can be set by sending 'value' - (ex. 0.01 for settin *value=0.01)

Definition at line 381 of file Commander.cpp.

Member Data Documentation

◆ com_port

Stream* Commander::com_port = nullptr

Serial terminal variable if provided.

Definition at line 93 of file Commander.h.

◆ decimal_places

uint8_t Commander::decimal_places = 3

number of decimal places to be used when displaying numbers

Definition at line 90 of file Commander.h.

◆ verbose

flag signaling that the commands should output user understanable text

Definition at line 89 of file Commander.h.


The documentation for this class was generated from the following files: