3#include <VirtualRobot/Nodes/RobotNode.h>
4#include <VirtualRobot/Robot.h>
17 NJointControllerRegistration<NJointZeroTorqueOrVelocityController>
19 "NJointZeroTorqueOrVelocityController");
24 return "NJointZeroTorqueOrVelocityController";
29 const NJointZeroTorqueOrVelocityControllerConfigPtr& config,
33 RobotUnitPtr robotUnit = RobotUnitPtr::dynamicCast(prov);
37 not(config->jointNamesZeroTorque.empty() and config->jointNamesZeroVelocity.empty()));
40 for (
auto& jointName : config->jointNamesZeroTorque)
42 if (std::find(config->jointNamesZeroVelocity.begin(),
43 config->jointNamesZeroVelocity.end(),
44 jointName) != config->jointNamesZeroVelocity.end())
46 ARMARX_ERROR << jointName <<
" exists in both torque and velocity controlled mode";
48 auto node = r->getRobotNode(jointName);
56 for (
auto& jointName : config->jointNamesZeroVelocity)
58 auto node = r->getRobotNode(jointName);
63 targetsVel.push_back(ct->
asA<ControlTarget1DoFActuatorZeroVelocity>());
67 config->jointNamesZeroTorque.size() + config->jointNamesZeroVelocity.size();
74 target.targetTorqueOrVelocity = Ice::FloatSeq(numJoints, 0.0f);
87 const IceUtil::Time& timeSinceLastIteration)
89 size_t torqueIndex = 0;
111 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
112 const std::map<std::string, ConstSensorDevicePtr>&)
118 ::armarx::WidgetDescription::WidgetSeq widgets;
119 auto addSlider = [&](
const std::string& label,
float min,
float max,
float defaultValue)
121 widgets.emplace_back(
new Label(
false, label));
126 c_x->defaultValue = defaultValue;
128 widgets.emplace_back(c_x);
133 LabelPtr label =
new Label;
134 label->text =
"zero torque joints";
135 layout->children.emplace_back(label);
137 StringComboBoxPtr box =
new StringComboBox;
138 box->name =
"jointNamesZeroTorque";
139 box->defaultIndex = 0;
140 box->multiSelect =
true;
142 for (
auto&
c : controlDevices)
144 if (
c.second->hasJointController(ControlModes::ZeroTorque1DoF))
146 box->options.push_back(
c.first);
149 layout->children.emplace_back(box);
153 LabelPtr labelControlMode =
new Label;
154 labelControlMode->text =
"zero velocity joints";
155 layout->children.emplace_back(labelControlMode);
157 StringComboBoxPtr boxControlMode =
new StringComboBox;
158 boxControlMode->name =
"jointNamesZeroVelocity";
159 boxControlMode->defaultIndex = 0;
160 boxControlMode->multiSelect =
true;
162 for (
auto&
c : controlDevices)
164 if (
c.second->hasJointController(ControlModes::ZeroVelocity1DoF))
166 boxControlMode->options.push_back(
c.first);
169 layout->children.emplace_back(boxControlMode);
172 addSlider(
"maxTorque", 0, 100, 10);
173 addSlider(
"maxVeloicty", 0, 3.14, 2.0);
175 layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
186 NJointZeroTorqueOrVelocityControllerConfigPtr
190 auto varZeroTorque = VariantPtr::dynamicCast(values.at(
"jointNamesZeroTorque"));
192 auto varZeroVelocity = VariantPtr::dynamicCast(values.at(
"jointNamesZeroVelocity"));
194 for (
auto& pair : values)
196 std::cout << pair.first;
203 values.at(
"maxTorque")->getFloat(),
204 values.at(
"maxVeloicty")->getFloat()};
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
Brief description of class JointControlTargetBase.
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
const NJointZeroTorqueOrVelocityControllerTarget & rtGetControlStruct() const
MutexType controlDataMutex
std::lock_guard< std::recursive_mutex > LockGuardType
void writeControlStruct()
NJointZeroTorqueOrVelocityControllerTarget & getWriterControlStruct()
void reinitTripleBuffer(const NJointZeroTorqueOrVelocityControllerTarget &initial)
The SingleTypeVariantList class is a subclass of VariantContainer and is comparable to a std::vector<...
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
std::vector< ControlTarget1DoFActuatorZeroVelocity * > targetsVel
void setControllerTarget(const Ice::FloatSeq &, const Ice::Current &) override
NJointZeroTorqueOrVelocityController(RobotUnitPtr prov, const NJointZeroTorqueOrVelocityControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
std::vector< ControlTarget1DoFActuatorZeroTorque * > targetsTorque
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
static NJointZeroTorqueOrVelocityControllerConfigPtr GenerateConfigFromVariants(const StringVariantBaseMap &values)
std::string getClassName(const Ice::Current &) const override
void rtPreActivateController() override
This function is called before the controller is activated.
std::vector< bool > torqueControlled
static double LimitTo(double value, double absThreshold)
Brief description of class targets.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
std::shared_ptr< class Robot > RobotPtr
NJointControllerRegistration< NJointZeroTorqueOrVelocityController > registrationControllerNJointZeroTorqueOrVelocityController("NJointZeroTorqueOrVelocityController")
std::map< std::string, VariantBasePtr > StringVariantBaseMap
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
IceUtil::Handle< class RobotUnit > RobotUnitPtr
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)