Skip to content

Commit

Permalink
Extend joint mode interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilario Tome authored and bmagyar committed Dec 31, 2019
1 parent bb60e00 commit ebb481e
Showing 1 changed file with 59 additions and 50 deletions.
109 changes: 59 additions & 50 deletions hardware_interface/include/hardware_interface/joint_mode_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,76 +34,85 @@

/* Author: Dave Coleman
Desc: This interface is for switching a hardware interface between different controller modes
i.e. position, velocity, force
i.e. position, velocity, effort
*/

#ifndef HARDWARE_INTERFACE_JOINT_MODE_INTERFACE_H
#define HARDWARE_INTERFACE_JOINT_MODE_INTERFACE_H
#pragma once

#include <cassert>
#include <hardware_interface/internal/hardware_resource_manager.h>

namespace hardware_interface
{

enum JointCommandModes {
MODE_POSITION = 1,
MODE_VELOCITY = 2,
MODE_EFFORT = 3,
MODE_OTHER = 4
};

/** \brief A handle used to read and mode a single joint. */
class JointModeHandle
{
public:
enum class JointCommandModes
{
BEGIN = -1,
MODE_POSITION = 0,
MODE_VELOCITY = 1,
MODE_EFFORT = 2,
NOMODE = 3,
EMERGENCY_STOP = 4,
SWITCHING = 5,
ERROR = 6
};

/**
* \param mode Which mode to start in
*/
JointModeHandle(std::string name, JointCommandModes* mode)
: mode_(mode)
, name_(name)
/** \brief A handle used to read and mode a single joint. */
class JointModeHandle
{
if (!mode_)
public:

JointModeHandle():
name_(), mode_(0){}

/** \param mode Which mode to start in */
JointModeHandle(std::string name, JointCommandModes* mode)
: mode_(mode)
, name_(name)
{
throw HardwareInterfaceException("Cannot create mode interface. Mode data pointer is null.");
if (!mode_)
{
throw HardwareInterfaceException("Cannot create mode interface. Mode data pointer is null.");
}
}
}

std::string getName() const {return name_;}
std::string getName() const {return name_;}

void setMode(JointCommandModes mode) {assert(mode_); *mode_ = mode;}
int getMode() const {assert(mode_); return *mode_;}
const int* getModePtr() const {assert(mode_); return mode_;}
JointCommandModes getMode() const {assert(mode_); return *mode_;}
const JointCommandModes* getModePtr() const {assert(mode_); return mode_;}

// Helper function for console messages
std::string getModeName(JointCommandModes mode)
{
switch(mode)
// Helper function for console messages
std::string getModeName(JointCommandModes mode) const
{
case MODE_POSITION:
return "position";
case MODE_VELOCITY:
return "velocity";
case MODE_EFFORT:
return "effort";
case MODE_OTHER:
return "other";
switch(mode)
{
case JointCommandModes::BEGIN:
return "not_operational";
case JointCommandModes::MODE_POSITION:
return "position";
case JointCommandModes::MODE_VELOCITY:
return "velocity";
case JointCommandModes::MODE_EFFORT:
return "effort";
case JointCommandModes::NOMODE:
return "other";
case JointCommandModes::EMERGENCY_STOP:
return "emergency_stop";
case JointCommandModes::SWITCHING:
return "switching";
case JointCommandModes::ERROR:
return "error";
}
return "unknown";
}
return "unknown";
}

private:
JointCommandModes* mode_;
std::string name_;
};
private:
JointCommandModes* mode_;
std::string name_;
};

/** \brief Hardware interface to support changing between control modes
*
*/
class JointModeInterface : public HardwareResourceManager<JointModeHandle, ClaimResources> {};
/** \brief Hardware interface to support changing between control modes */
class JointModeInterface : public HardwareResourceManager<JointModeHandle, DontClaimResources> {};

} // namespace

#endif

0 comments on commit ebb481e

Please sign in to comment.