Namespace package_template

namespace package_template

Functions

void print_configuration(const Gains_configuration &configuration)

print values encapsulated by the provided configuration console on the standard output

PID &get_default_pid()

convenience factory for getting default controller, i.e.

same as PID(std::shared_ptr<DefaultConfiguration> configuration)

See

DefaultConfiguration

bool get_parameter(const ros::NodeHandle &nh, const std::string &parameter, double &get_value)
class Default_pid_factory

Use a PID factory for the unittests.

Public Static Functions

PID &get()

PID controller factory.

Return

PID& Return a reference to a newly created PID controller.

Public Static Attributes

std::vector<std::shared_ptr<Gains_configuration>> configs_

The PID gains.

std::vector<std::shared_ptr<PID>> controllers_

List of PID controllers.

class DefaultConfiguration : public package_template::Gains_configuration
#include <default_configuration.hpp>

Default configuration for the kp, kd, ki paramters.

This class initialize the PID gains as follow:

  • kp = DEFAULT_KP,

  • kd = DEFAULT_KD

  • ki = DEFAULT_KI

Public Functions

~DefaultConfiguration()

Here we use the default destructor.

double get_kp() const

Always returns DEFAULT_KP.

Return

double DEFAULT_KP

double get_kd() const

Always returns DEFAULT_KD.

Return

double DEFAULT_KD

double get_ki() const

Always returns DEFAULT_KI.

Return

double DEFAULT_KI

bool has_error() const

Always returns false.

Return

true Never

Return

false Always

std::string get_error() const

Always returns “no error”.

Return

std::string “no error”

class File_configuration : public package_template::Gains_configuration
#include <file_configuration.hpp>

Reading configuration from yaml file.

Public Functions

File_configuration(std::string yaml_file)

Returns error encountered when reading configuration.

See

has_error()

Parameters
  • yaml_file: absolute path to configuration yaml file. The file is expected to have parameters “kp”, “kd” and “ki”

double get_kp() const

Get the proportional gain.

Return

double

double get_kd() const

Get the derivative gain.

Return

double

double get_ki() const

Get the integral gain.

Return

double

bool has_error() const

Enquire if an error was encountered while reading the configuration.

See

get_error()

Return

true if an error has been encountered

Return

false otherwise

std::string get_error() const

returns error encountered when reading configuration

See

has_error()

Private Members

double kp_

Proportinal gain.

double kd_

Derivative gain.

double ki_

Integral gain.

std::string error_message_

Internal error message.

bool error_

True if an error occured.

class Gains_configuration
#include <gains_configuration.hpp>

Abstract class defining for the PID configuration.

This virtual object describes the configuration a PID objects is waiting for. Daughter class will for example be initialize through files, ROS params, etc.

Subclassed by package_template::DefaultConfiguration, package_template::File_configuration, package_template::RosParameters_configuration

Public Functions

~Gains_configuration()

The default destructor do nothing.

double get_kp() const = 0

Get the proportional gain.

Return

double

double get_kd() const = 0

Get the derivative gain.

Return

double

double get_ki() const = 0

Get the integral gain.

Return

double

bool has_error() const = 0

Enquire if an error was encountered while reading the configuration.

See

get_error()

Return

true if an error has been encountered

Return

false otherwise

std::string get_error() const = 0

returns error encountered when reading configuration

See

has_error()

class PID
#include <pid.hpp>

Simple 1D pid controller.

Public Functions

PID()

Construct a default PID object using the DefaultConfiguration.

PID(const Gains_configuration &configuration)

Construct a new PID object using a user provided configuration.

Parameters
  • configuration:

~PID()
double compute(const double position, const double velocity, const double position_target, const double delta_time)

compute the force related to the pid controller.

Warning

this function is not stateless, as it performs integration. Call reset_pid() to reset the integral part.

Return

computed force

Parameters
  • position: current position

  • velocity: current velocity

  • position_target: target position

  • delta_time: time passed since last measurement. Used for integral computation

void reset_integral()

reset integral part of the PID

Private Members

const Gains_configuration *configuration_
bool private_configuration_
double integral_
class RosParameters_configuration : public package_template::Gains_configuration
#include <rosparameters_configuration.hpp>

Read gains configuration from the ros parameter server.

Public Functions

RosParameters_configuration()

Attempt to get the gains from the parameter server (“gains_kp”,”gains_kd”,”gains_ki” parameters) If roscore is running, calls to this constructor will be blocking until all the gains are read or roscore is turned off.

If roscore is turned off before gains are read, has_error() will return true

See

has_error()

double get_kp() const

Get the proportinal gain.

double get_kd() const

Get the derivative gain.

double get_ki() const

get the integral gain

bool has_error() const

Check if there are internal errors

std::string get_error() const

Get the error messages

Private Members

double kp_

Proportinal gain.

double kd_

Derivative gain.

double ki_

Integral gain.

std::string error_message_

Internal error message.

bool error_

True is an error occured.