Choreonoid  1.8
DigitalIoDevice.h
Go to the documentation of this file.
1 #ifndef CNOID_BODY_DIGITAL_IO_DEVICE_H
2 #define CNOID_BODY_DIGITAL_IO_DEVICE_H
3 
4 #include "Device.h"
5 #include <vector>
6 #include "exportdecl.h"
7 
8 namespace cnoid {
9 
10 class Mapping;
11 
12 class CNOID_EXPORT DigitalIoDevice : public Device
13 {
14 public:
16  virtual ~DigitalIoDevice();
17 
18  virtual const char* typeName() const override;
19  void copyDigitalIoDeviceStateFrom(const DigitalIoDevice& other);
20  virtual void copyStateFrom(const DeviceState& other) override;
21  virtual DeviceState* cloneState() const override;
22  virtual void forEachActualType(std::function<bool(const std::type_info& type)> func) override;
23  virtual int stateSize() const override;
24  virtual const double* readState(const double* buf) override;
25  virtual double* writeState(double* out_buf) const override;
26 
27  virtual bool on() const override;
28  virtual void on(bool on) override;
29 
30  int numSignalLines() const { return out_.size(); }
31  void setNumSignalLines(int n);
32 
33  bool out(int index) const { return out_[index]; }
34  void setOut(int index, bool on, bool doNotify = true);
35  bool in(int index) const { return in_[index]; }
36  void setIn(int index, bool on, bool doNotify = true);
37 
38  const std::string& outLabel(int index) const;
39  void setOutLabel(int index, const std::string& label);
40  std::vector<std::pair<int, std::string&>> getOutLabels() const;
41  const std::string& inLabel(int index) const;
42  void setInLabel(int index, const std::string& label);
43  std::vector<std::pair<int, std::string&>> getInLabels() const;
44 
45  SignalProxy<void(bool on)> sigOutput(int index);
46  SignalProxy<void(bool on)> sigInput(int index);
47 
48  bool readDescription(const Mapping* info);
49  bool readSpecifications(const Mapping* info);
50  bool readConfiguration(const Mapping* info);
51  bool writeDescription(Mapping* info) const;
52  bool writeSpecifications(Mapping* info) const;
53  bool writeConfiguration(Mapping* info) const;
54 
55  // Tentative api. The role of this API will be replaced with the StdActionController device.
56  void setInputToDeviceSwitchConnection(int inputIndex, const std::string& deviceName);
57  std::vector<std::pair<int, std::string&>> getInputToDeviceSwitchConnections() const;
58  void removeInputToDeviceSwitchConnection(int inputIndex);
59  void clearInputToDeviceSwitchConnections();
60  bool readInputToDeviceSwitchConnections(const Mapping& archive);
61 
62 protected:
63  DigitalIoDevice(const DigitalIoDevice& org, bool copyStateOnly, CloneMap* cloneMap);
64  virtual Referenced* doClone(CloneMap* cloneMap) const override;
65 
66 private:
67  std::vector<bool> out_;
68  std::vector<bool> in_;
69  bool on_;
70 
71  class Impl;
72  Impl* impl;
73 };
74 
76 
77 }
78 
79 #endif
cnoid::DigitalIoDevice::in
bool in(int index) const
Definition: DigitalIoDevice.h:35
cnoid::DigitalIoDevice
Definition: DigitalIoDevice.h:12
cnoid::Mapping
Definition: ValueTree.h:253
Device.h
cnoid::ref_ptr< DigitalIoDevice >
cnoid::DigitalIoDevicePtr
ref_ptr< DigitalIoDevice > DigitalIoDevicePtr
Definition: DigitalIoDevice.h:75
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::CloneMap
Definition: CloneMap.h:13
cnoid::DeviceState
Definition: Device.h:20
cnoid::DigitalIoDevice::numSignalLines
int numSignalLines() const
Definition: DigitalIoDevice.h:30
cnoid::DigitalIoDevice::out
bool out(int index) const
Definition: DigitalIoDevice.h:33
cnoid::Referenced
Definition: Referenced.h:54
cnoid::Device
Definition: Device.h:53
cnoid::SignalProxy
Definition: Signal.h:470