Choreonoid  1.5
Device.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_BODY_DEVICE_H
7 #define CNOID_BODY_DEVICE_H
8 
9 #include <cnoid/EigenTypes>
10 #include <cnoid/Signal>
11 #include <string>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class Link;
17 
19 {
20 protected:
22  DeviceState(const DeviceState& org) { }
23 
24 public:
25  virtual ~DeviceState() { }
26 
27  virtual const char* typeName() = 0;
28 
29  virtual void copyStateFrom(const DeviceState& other) = 0;
30  virtual DeviceState* cloneState() const = 0;
31 
35  virtual int stateSize() const = 0;
36 
41  virtual const double* readState(const double* buf) = 0;
42 
47  virtual double* writeState(double* out_buf) const = 0;
48 };
50 
51 
53 {
54  struct NonState {
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56  int index; // automatically assigned
57  int id; // pre-defined id
58  std::string name;
59  Link* link;
60  Isometry3 T_local;
61  double cycle;
62  const Isometry3& const_T_local() const { return T_local; }
63  Signal<void()> sigStateChanged;
64  };
65 
66  NonState* ns;
67 
68 protected:
69  Device();
70  Device(const Device& org, bool copyStateOnly = false);
71 
72 public:
73  virtual ~Device();
74 
75  void setIndex(int index) { ns->index = index; }
76  void setId(int id) { ns->id = id; }
77  void setName(const std::string& name) { ns->name = name; }
78  void setLink(Link* link) { ns->link = link; }
79 
80  virtual Device* clone() const = 0;
81  virtual void forEachActualType(boost::function<bool(const std::type_info& type)> func);
82  virtual void clearState();
83 
84  bool hasStateOnly() const { return (ns != 0); }
85 
86  const int index() const { return ns->index; }
87  const int id() const { return ns->id; }
88  const std::string& name() const { return ns->name; }
89 
90  const Link* link() const { return ns->link; }
91  Link* link() { return ns->link; }
92 
93  Isometry3& T_local() { return ns->T_local; }
94  const Isometry3& T_local() const { return ns->T_local; }
95 
96  Isometry3::ConstLinearPart R_local() const { return ns->const_T_local().linear(); }
97  Isometry3::LinearPart R_local() { return ns->T_local.linear(); }
98 
99  Isometry3::ConstLinearPart localRotation() const { return ns->const_T_local().linear(); }
100  Isometry3::LinearPart localRotaion() { return ns->T_local.linear(); }
101 
102  template<typename Derived>
103  void setLocalRotation(const Eigen::MatrixBase<Derived>& R) { ns->T_local.linear() = R; }
104 
105  Isometry3::ConstTranslationPart p_local() const { return ns->const_T_local().translation(); }
106  Isometry3::TranslationPart p_local() { return ns->T_local.translation(); }
107 
108  Isometry3::ConstTranslationPart localTranslation() const { return ns->const_T_local().translation(); }
109  Isometry3::TranslationPart localTranslation() { return ns->T_local.translation(); }
110 
111  template<typename Derived>
112  void setLocalTranslation(const Eigen::MatrixBase<Derived>& p) { ns->T_local.translation() = p; }
113 
114  double cycle() const { return ns->cycle; }
115  void setCycle(double msec) { ns->cycle = msec; }
116 
118  return ns->sigStateChanged;
119  }
120 
122  ns->sigStateChanged();
123  }
124 
125 };
126 
128 
129 };
130 
131 #endif
void notifyStateChange()
Definition: Device.h:121
void setName(const std::string &name)
Definition: Device.h:77
Isometry3 & T_local()
Definition: Device.h:93
Isometry3::LinearPart R_local()
Definition: Device.h:97
Link * link()
Definition: Device.h:91
const int index() const
Definition: Device.h:86
ref_ptr< DeviceState > DeviceStatePtr
Definition: Device.h:49
const Isometry3 & T_local() const
Definition: Device.h:94
DeviceState()
Definition: Device.h:21
double cycle() const
Definition: Device.h:114
Isometry3::ConstLinearPart localRotation() const
Definition: Device.h:99
void setId(int id)
Definition: Device.h:76
Definition: Referenced.h:67
SignalProxy< void()> sigStateChanged()
Definition: Device.h:117
void setLocalTranslation(const Eigen::MatrixBase< Derived > &p)
Definition: Device.h:112
void setIndex(int index)
Definition: Device.h:75
Isometry3::ConstTranslationPart localTranslation() const
Definition: Device.h:108
const Link * link() const
Definition: Device.h:90
void setLink(Link *link)
Definition: Device.h:78
Definition: Device.h:18
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:78
Isometry3::ConstTranslationPart p_local() const
Definition: Device.h:105
Isometry3::ConstLinearPart R_local() const
Definition: Device.h:96
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
ref_ptr< Device > DevicePtr
Definition: Device.h:127
DeviceState(const DeviceState &org)
Definition: Device.h:22
void setLocalRotation(const Eigen::MatrixBase< Derived > &R)
Definition: Device.h:103
virtual ~DeviceState()
Definition: Device.h:25
Isometry3::LinearPart localRotaion()
Definition: Device.h:100
const int id() const
Definition: Device.h:87
Isometry3::TranslationPart localTranslation()
Definition: Device.h:109
Isometry3::TranslationPart p_local()
Definition: Device.h:106
#define CNOID_EXPORT
Definition: Util/exportdecl.h:37
Definition: Signal.h:380
bool hasStateOnly() const
Definition: Device.h:84
const std::string & name() const
Definition: Device.h:88
void setCycle(double msec)
Definition: Device.h:115
Definition: Device.h:52