Privacy
An open-source, flexible 3D physical simulation framework
mars::sim::MotorManager Class Reference

"MotorManager" imlements the interfaces for all motor operations that are used for the communication between the simulation modules. More...

#include <MotorManager.h>

Public Member Functions

 MotorManager (interfaces::ControlCenter *c)
 Constructor. More...
 
virtual ~MotorManager ()
 Destructor. More...
 
virtual unsigned long addMotor (interfaces::MotorData *motorS, bool reload=false)
 Add a motor to the simulation. More...
 
virtual int getMotorCount () const
 Returns the number of motors that are currently present in the simulation. More...
 
virtual void editMotor (const interfaces::MotorData &motorS)
 Change motor properties. More...
 
virtual void getListMotors (std::vector< interfaces::core_objects_exchange > *motorList) const
 Gives information about core exchange data for motors. More...
 
virtual const interfaces::MotorData getFullMotor (unsigned long index) const
 Gives all information of a certain motor. More...
 
virtual void removeMotor (unsigned long index)
 Removes a motor from the simulation. More...
 
virtual SimMotorgetSimMotor (unsigned long id) const
 This function returns the SimMotor object for a given id. More...
 
virtual SimMotorgetSimMotorByName (const std::string &name) const
 This function returns the SimMotor object for a given name. More...
 
virtual void setMotorValue (unsigned long id, interfaces::sReal value)
 Sets the value of the motor with the given id to the given value. More...
 
virtual void setMaxTorque (unsigned long id, interfaces::sReal maxTorque)
 Sets the maximum torque of the motor with the given id to the given value. More...
 
virtual void setMaxSpeed (unsigned long id, interfaces::sReal maxSpeed)
 Sets the maximum speed of the motor with the given id to the given value. More...
 
virtual void setMotorValueDesiredVelocity (unsigned long id, interfaces::sReal velocity)
 Sets the desired speed of a motor. More...
 
virtual void setMotorP (unsigned long id, interfaces::sReal value)
 Sets the proportional term of the motor with the given id to the given value. More...
 
virtual void setMotorI (unsigned long id, interfaces::sReal value)
 Sets the integral term of the motor with the given id to the given value. More...
 
virtual void setMotorD (unsigned long id, interfaces::sReal value)
 Sets the derivative term of the motor with the given id to the given value. More...
 
virtual void deactivateMotor (unsigned long id)
 Deactivates the motor with the given id. More...
 
virtual void clearAllMotors (bool clear_all=false)
 Destroys all motors in the simulation. More...
 
virtual void reloadMotors (void)
 This function reloads all motors from a temporary motor pool. More...
 
virtual void updateMotors (interfaces::sReal calc_ms)
 This function updates all motors with timing value calc_ms in miliseconds. More...
 
virtual interfaces::sReal getActualPosition (unsigned long motorId) const
 
virtual interfaces::sReal getTorque (unsigned long motorId) const
 
virtual void moveMotor (unsigned long index, interfaces::sReal value)
 Sets the value of the motor with the given id to the given value. More...
 
virtual void removeJointFromMotors (unsigned long joint_index)
 Detaches the joint with the given index from all motors that act on it, if any. More...
 
virtual unsigned long getID (const std::string &motor_name) const
 Retrieves the id of a motor by name. More...
 
virtual void getDataBrokerNames (unsigned long jointId, std::string *groupName, std::string *dataName) const
 Retrieves the groupName and dataName under which the motor with the specified id publishes its data in the DataBroker. More...
 
virtual void connectMimics ()
 
virtual void edit (interfaces::MotorId id, const std::string &key, const std::string &value)
 
- Public Member Functions inherited from mars::interfaces::MotorManagerInterface
virtual ~MotorManagerInterface ()
 Destructor. More...
 

Private Attributes

unsigned long next_motor_id
 the id of the next motor that is added to the simulation More...
 
std::map< unsigned long, SimMotor * > simMotors
 a container for all motors currently present in the simulation More...
 
std::list< interfaces::MotorDatasimMotorsReload
 a containter for all motors that are reloaded after a reset of the simulation More...
 
interfaces::ControlCentercontrol
 a pointer to the control center More...
 
utils::Mutex iMutex
 a mutex for the motor containters More...
 
std::map< unsigned long, std::string > mimicmotors
 

Detailed Description

"MotorManager" imlements the interfaces for all motor operations that are used for the communication between the simulation modules.

Inherits from MotorManagerInterface.

Warning
It is very important to assure the serialization between the threads to have the desired results. Currently the verified use of the functions is only guaranteed by calling it within the main thread (update callback from gui_thread).

Definition at line 60 of file MotorManager.h.

Constructor & Destructor Documentation

◆ MotorManager()

mars::sim::MotorManager::MotorManager ( interfaces::ControlCenter c)

Constructor.

Parameters
cThe pointer to the ControlCenter of the simulation.

Definition at line 59 of file MotorManager.cpp.

◆ ~MotorManager()

virtual mars::sim::MotorManager::~MotorManager ( )
inlinevirtual

Destructor.

Definition at line 73 of file MotorManager.h.

Member Function Documentation

◆ addMotor()

unsigned long mars::sim::MotorManager::addMotor ( interfaces::MotorData motorS,
bool  reload = false 
)
virtual

Add a motor to the simulation.

Parameters
motorSA pointer to the MotorData that defines the new motor.
reloadUsed internally by the simulation. The default value is false. If this param is set to true the new motor will not be reloaded after a reset of the simulation.
Returns
The unique id of the newly added motor.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 77 of file MotorManager.cpp.

◆ clearAllMotors()

void mars::sim::MotorManager::clearAllMotors ( bool  clear_all = false)
virtual

Destroys all motors in the simulation.

The clear_all flag indicates if the reload motors should be destroyed as well. If set to false they are left intact.

Parameters
clear_allIndicates if the reload motors should be destroyed as well. If set to false they are left intact.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 428 of file MotorManager.cpp.

◆ connectMimics()

void mars::sim::MotorManager::connectMimics ( )
virtual

Implements mars::interfaces::MotorManagerInterface.

Definition at line 536 of file MotorManager.cpp.

◆ deactivateMotor()

void mars::sim::MotorManager::deactivateMotor ( unsigned long  id)
virtual

Deactivates the motor with the given id.

Parameters
idThe id of the motor that is to be deactivated.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 373 of file MotorManager.cpp.

◆ edit()

void mars::sim::MotorManager::edit ( interfaces::MotorId  id,
const std::string &  key,
const std::string &  value 
)
virtual

Implements mars::interfaces::MotorManagerInterface.

Definition at line 545 of file MotorManager.cpp.

◆ editMotor()

void mars::sim::MotorManager::editMotor ( const interfaces::MotorData motorS)
virtual

Change motor properties.

The old struct is replaced by the new one completely, so prior to calling this function, one must ensure that all properties of this parameter are valid and as desired.

Parameters
motorSThe id of the MotorData referred by this pointer must be the same as the id of the motor that is to be edited.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 168 of file MotorManager.cpp.

◆ getActualPosition()

sReal mars::sim::MotorManager::getActualPosition ( unsigned long  motorId) const
virtual
Returns
the actual position of the motor with the given Id. returns 0 if a motor with the given Id doesn't exist.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 474 of file MotorManager.cpp.

◆ getDataBrokerNames()

void mars::sim::MotorManager::getDataBrokerNames ( unsigned long  jointId,
std::string *  groupName,
std::string *  dataName 
) const
virtual

Retrieves the groupName and dataName under which the motor with the specified id publishes its data in the DataBroker.

Returns
true if the names were successfully retrieved. false if no motor with the given id exists.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 527 of file MotorManager.cpp.

◆ getFullMotor()

const MotorData mars::sim::MotorManager::getFullMotor ( unsigned long  index) const
virtual

Gives all information of a certain motor.

Parameters
indexThe unique id of the motor to get information for.
Returns
A pointer to the MotorData of the motor with the given id.
Parameters
indexThe unique id of the motor to get information for.
Returns
A pointer to the MotorData of the motor with the given id.
Exceptions
std::runtime_errorif a motor with the given index does not exist.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 204 of file MotorManager.cpp.

◆ getID()

unsigned long mars::sim::MotorManager::getID ( const std::string &  name) const
virtual

Retrieves the id of a motor by name.

Parameters
motor_nameName of the motor to get the id for
Returns
Id of the motor if it exists, otherwise 0

Implements mars::interfaces::MotorManagerInterface.

Definition at line 388 of file MotorManager.cpp.

◆ getListMotors()

void mars::sim::MotorManager::getListMotors ( std::vector< interfaces::core_objects_exchange > *  motorList) const
virtual

Gives information about core exchange data for motors.

Parameters
motorListA pointer to a vector that is filled with a core_objects_exchange struct for every motor and its index. The vector is cleared in the beginning of this function.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 183 of file MotorManager.cpp.

◆ getMotorCount()

int mars::sim::MotorManager::getMotorCount ( ) const
virtual

Returns the number of motors that are currently present in the simulation.

Returns
The number of all motors.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 152 of file MotorManager.cpp.

◆ getSimMotor()

SimMotor * mars::sim::MotorManager::getSimMotor ( unsigned long  id) const
virtual

This function returns the SimMotor object for a given id.

Warning
This method is only internal used by the MotorManager. Generally no other modules know the SimMotor class and shouldn't use this method. All motor operations from outside the core should be done over the MotorManager.
Parameters
indexThe id of the motor to get the core node object.
Returns
Returns a pointer to the corresponding motor object.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 250 of file MotorManager.cpp.

◆ getSimMotorByName()

SimMotor * mars::sim::MotorManager::getSimMotorByName ( const std::string &  name) const
virtual

This function returns the SimMotor object for a given name.

Warning
This method is only internal used by the MotorManager. Generally no other modules know the SimMotor class and shouldn't use this method. All motor operations from outside the core should be done over the MotorManager.
Parameters
nameThe name of the motor to get the core node object.
Returns
Returns a pointer to the corresponding motor object.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 273 of file MotorManager.cpp.

◆ getTorque()

sReal mars::sim::MotorManager::getTorque ( unsigned long  motorId) const
virtual
Returns
the torque excerted by the motor with the given Id. returns 0 if a motor with the given Id doesn't exist.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 483 of file MotorManager.cpp.

◆ moveMotor()

void mars::sim::MotorManager::moveMotor ( unsigned long  index,
interfaces::sReal  value 
)
virtual

Sets the value of the motor with the given id to the given value.

Essentially this function triggers the motor and moves the joint that is attached to it. Equivalent to setMotorValue

Parameters
idThe id of the motor whose value is to be changed.
valueThe new value.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 411 of file MotorManager.cpp.

◆ reloadMotors()

void mars::sim::MotorManager::reloadMotors ( void  )
virtual

This function reloads all motors from a temporary motor pool.

All motors that have been added with reload value as true are added back to the simulation again with a reload value of true.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 446 of file MotorManager.cpp.

◆ removeJointFromMotors()

void mars::sim::MotorManager::removeJointFromMotors ( unsigned long  joint_index)
virtual

Detaches the joint with the given index from all motors that act on it, if any.

Used when a joint is destroyed.

Warning
The detached motors are not destroyed and are still present in the simulation, although they do not have any effect on it. A call to removeMotor must be made to remove the motor completely.
Parameters
joint_indexThe id of the joint that is to be detached.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 519 of file MotorManager.cpp.

◆ removeMotor()

void mars::sim::MotorManager::removeMotor ( unsigned long  index)
virtual

Removes a motor from the simulation.

Parameters
indexThe unique id of the motor to remove form the simulation.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 222 of file MotorManager.cpp.

◆ setMaxSpeed()

void mars::sim::MotorManager::setMaxSpeed ( unsigned long  id,
interfaces::sReal  maxSpeed 
)
virtual

Sets the maximum speed of the motor with the given id to the given value.

Parameters
idThe id of the motor whose value is to be changed.
maxSpeedThe new maximum speed for the motor.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 500 of file MotorManager.cpp.

◆ setMaxTorque()

void mars::sim::MotorManager::setMaxTorque ( unsigned long  id,
interfaces::sReal  maxTorque 
)
virtual

Sets the maximum torque of the motor with the given id to the given value.

Parameters
idThe id of the motor whose value is to be changed.
maxTorqueThe new maximum torque for the motor.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 492 of file MotorManager.cpp.

◆ setMotorD()

void mars::sim::MotorManager::setMotorD ( unsigned long  id,
interfaces::sReal  value 
)
virtual

Sets the derivative term of the motor with the given id to the given value.

Only has effect on a PID motor. If the type of the motor with the given id is different from PID, no effect is observed, although the D value of the motor object is still changed.

Parameters
idThe id of the motor whose D value is to be changed.
valueThe new D value.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 360 of file MotorManager.cpp.

◆ setMotorI()

void mars::sim::MotorManager::setMotorI ( unsigned long  id,
interfaces::sReal  value 
)
virtual

Sets the integral term of the motor with the given id to the given value.

Only has effect on a PID motor. If the type of the motor with the given id is different from PID, no effect is observed, although the I value of the motor object is still changed.

Parameters
idThe id of the motor whose I value is to be changed.
valueThe new I value.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 341 of file MotorManager.cpp.

◆ setMotorP()

void mars::sim::MotorManager::setMotorP ( unsigned long  id,
interfaces::sReal  value 
)
virtual

Sets the proportional term of the motor with the given id to the given value.

Only has effect on a PID motor. If the type of the motor with the given id is different from PID, no effect is observed, although the P value of the motor object is still changed.

Parameters
idThe id of the motor whose P value is to be changed.
valueThe new P value.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 322 of file MotorManager.cpp.

◆ setMotorValue()

void mars::sim::MotorManager::setMotorValue ( unsigned long  id,
interfaces::sReal  value 
)
virtual

Sets the value of the motor with the given id to the given value.

Essentially this function triggers the motor and moves the joint that is attached to it. Equivalent to moveMotor

Parameters
idThe id of the motor whose value is to be changed.
valueThe new value.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 294 of file MotorManager.cpp.

◆ setMotorValueDesiredVelocity()

void mars::sim::MotorManager::setMotorValueDesiredVelocity ( unsigned long  id,
interfaces::sReal  velocity 
)
virtual

Sets the desired speed of a motor.

Parameters
idThe id of the motor whose value is to be changed.
valueThe new value in rad/s.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 302 of file MotorManager.cpp.

◆ updateMotors()

void mars::sim::MotorManager::updateMotors ( interfaces::sReal  calc_ms)
virtual

This function updates all motors with timing value calc_ms in miliseconds.

Warning
This function is only used internally and should not be called outside the core.
Parameters
calc_msThe timing value in miliseconds.

Implements mars::interfaces::MotorManagerInterface.

Definition at line 466 of file MotorManager.cpp.

Member Data Documentation

◆ control

interfaces::ControlCenter* mars::sim::MotorManager::control
private

a pointer to the control center

Definition at line 331 of file MotorManager.h.

◆ iMutex

utils::Mutex mars::sim::MotorManager::iMutex
mutableprivate

a mutex for the motor containters

Definition at line 334 of file MotorManager.h.

◆ mimicmotors

std::map<unsigned long, std::string> mars::sim::MotorManager::mimicmotors
private

Definition at line 337 of file MotorManager.h.

◆ next_motor_id

unsigned long mars::sim::MotorManager::next_motor_id
private

the id of the next motor that is added to the simulation

Definition at line 322 of file MotorManager.h.

◆ simMotors

std::map<unsigned long, SimMotor*> mars::sim::MotorManager::simMotors
private

a container for all motors currently present in the simulation

Definition at line 325 of file MotorManager.h.

◆ simMotorsReload

std::list<interfaces::MotorData> mars::sim::MotorManager::simMotorsReload
private

a containter for all motors that are reloaded after a reset of the simulation

Definition at line 328 of file MotorManager.h.


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