Franky 0.12.0
A High-Level Motion API for Franka
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dynamics_limit.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <mutex>
6#include <sstream>
7#include <stdexcept>
8#include <string>
9
10namespace franky {
11
20template <typename LimitType>
22 public:
34 DynamicsLimit(const std::string& desc, const LimitType& max_val, const LimitType& default_val,
35 const std::shared_ptr<std::mutex>& write_mutex, const std::function<bool()>& can_write_condition)
36 : max(max_val),
37 desc(desc),
38 write_mutex_(write_mutex),
39 value_(default_val),
40 can_write_condition_(can_write_condition) {}
41
50 template <typename AlternativeType>
51 void setFrom(const AlternativeType& value);
52
63 void set(const LimitType& value) {
64 std::unique_lock lock(*write_mutex_);
65 if (!can_write_condition_()) {
66 std::stringstream ss;
67 ss << "Cannot set " << desc << " limit while robot is in control.";
68 throw std::runtime_error(ss.str());
69 }
70 check(value);
71 value_ = value;
72 }
73
81 [[nodiscard]] LimitType get() const { return value_; }
82
88 const LimitType max;
89
95 const std::string desc;
96
97 template <typename LimitTypeStream>
98 friend std::ostream& operator<<(std::ostream& os, const DynamicsLimit<LimitTypeStream>& dynamics_limit);
99
100 private:
109 void check(const LimitType& value) const;
110
111 std::shared_ptr<std::mutex> write_mutex_;
112 LimitType value_;
113 std::function<bool()> can_write_condition_;
114};
115
116template <typename LimitTypeStream>
117std::ostream& operator<<(std::ostream& os, const DynamicsLimit<LimitTypeStream>& dynamics_limit) {
118 os << dynamics_limit.value_ << " (max: " << dynamics_limit.max << ")";
119 return os;
120}
121
122} // namespace franky
A template class representing a dynamics limit with a maximum value.
Definition dynamics_limit.hpp:21
void set(const LimitType &value)
Set a new value for the limit.
Definition dynamics_limit.hpp:63
friend std::ostream & operator<<(std::ostream &os, const DynamicsLimit< LimitTypeStream > &dynamics_limit)
Definition dynamics_limit.hpp:117
LimitType get() const
Get the current value of the limit.
Definition dynamics_limit.hpp:81
const std::string desc
Description of this limit.
Definition dynamics_limit.hpp:95
DynamicsLimit(const std::string &desc, const LimitType &max_val, const LimitType &default_val, const std::shared_ptr< std::mutex > &write_mutex, const std::function< bool()> &can_write_condition)
Constructor for DynamicsLimit.
Definition dynamics_limit.hpp:34
const LimitType max
The maximum value this limit can take as defined by Franka.
Definition dynamics_limit.hpp:88
void setFrom(const AlternativeType &value)
Set a new value for the limit with a different type.
Definition dynamics_limit.cpp:8
std::ostream & operator<<(std::ostream &os, const DynamicsLimit< Vector7d > &limit)
Definition dynamics_limit.cpp:47