Firmware for Arduino | PLEN Project Company Inc.
JointController.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #ifndef PLEN2_JOINT_CONTROLLER_H
11 #define PLEN2_JOINT_CONTROLLER_H
12 
13 
14 #include <stdint.h>
15 
16 #include "BuildConfig.h"
17 
18 namespace PLEN2
19 {
20  class JointController;
21 }
22 
30 {
31 public:
33  {
52  };
53 
55  {
56  JOINTS_SUM = 24,
57 
58  #if TARGET_PLEN14
59  ANGLE_MIN = -600,
60  ANGLE_MAX = 600,
61  ANGLE_NEUTRAL = 0
62  #endif
63 
64  #if TARGET_PLEN20
65  ANGLE_MIN = -900,
66  ANGLE_MAX = 900,
67  ANGLE_NEUTRAL = 0
68  #endif
69  };
70 
71 private:
73  enum { INIT_FLAG_ADDRESS = 0 };
74 
76  enum { INIT_FLAG_VALUE = 3 };
77 
79  enum { SETTINGS_HEAD_ADDRESS = 1 };
80 
84  class JointSetting
85  {
86  public:
87  int16_t MIN;
88  int16_t MAX;
89  int16_t HOME;
90 
94  JointSetting()
95  : MIN(ANGLE_MIN)
96  , MAX(ANGLE_MAX)
97  , HOME(ANGLE_NEUTRAL)
98  {
99  // noop.
100  }
101  };
102 
103  JointSetting m_SETTINGS[JOINTS_SUM];
104 
105 public:
114  {
115  public:
117  enum { SUM = 3 };
118 
120  enum { SELECTABLE_LINES = 8 };
121  };
122 
123  #if TARGET_PLEN14
124  enum { PWM_MIN = 492 };
126 
128  enum { PWM_MAX = 816 };
129 
131  enum { PWM_NEUTRAL = 654 };
132  #endif
133 
134  #if TARGET_PLEN20
135  enum { PWM_MIN = 410 };
137 
139  enum { PWM_MAX = 884 };
140 
142  enum { PWM_NEUTRAL = 647 };
143  #endif
144 
153  volatile static bool m_1cycle_finished;
154 
163  static uint16_t m_pwms[JOINTS_SUM];
164 
168  JointController();
169 
184  void loadSettings();
185 
191  void resetSettings();
192 
201  const int16_t& getMinAngle(uint8_t joint_id);
202 
211  const int16_t& getMaxAngle(uint8_t joint_id);
212 
221  const int16_t& getHomeAngle(uint8_t joint_id);
222 
231  bool setMinAngle(uint8_t joint_id, int16_t angle);
232 
241  bool setMaxAngle(uint8_t joint_id, int16_t angle);
242 
251  bool setHomeAngle(uint8_t joint_id, int16_t angle);
252 
266  bool setAngle(uint8_t joint_id, int16_t angle);
267 
281  bool setAngleDiff(uint8_t joint_id, int16_t angle_diff);
282 
299  void dump();
300 };
301 
302 #endif // PLEN2_JOINT_CONTROLLER_H
const int16_t & getHomeAngle(uint8_t joint_id)
Get home angle of the joint given.
Definition: JointController.h:36
Definition: AccelerationGyroSensor.h:16
const int16_t & getMaxAngle(uint8_t joint_id)
Get max angle of the joint given.
JointController()
Constructor.
static volatile bool m_1cycle_finished
Finished flag of PWM output procedure 1 cycle.
Definition: JointController.h:153
bool setMinAngle(uint8_t joint_id, int16_t angle)
Set min angle of the joint given.
Definition: JointController.h:46
Definition: JointController.h:39
Definition: JointController.h:35
Definition: JointController.h:41
void resetSettings()
Reset the joint settings.
bool setMaxAngle(uint8_t joint_id, int16_t angle)
Set max angle of the joint given.
Management class (as namespace) of multiplexer.
Definition: JointController.h:113
static uint16_t m_pwms[JOINTS_SUM]
PWM buffer.
Definition: JointController.h:163
Definition: JointController.h:34
bool setAngleDiff(uint8_t joint_id, int16_t angle_diff)
Set angle to "angle-diff + home-angle" of the joint given.
bool setAngle(uint8_t joint_id, int16_t angle)
Set angle of the joint given.
Definition: JointController.h:40
Definition: JointController.h:48
void loadSettings()
Load the joint settings.
Summation of the servos controllable.
Definition: JointController.h:56
BASIC_JOINT_SETTINGS
Definition: JointController.h:54
Definition: JointController.h:117
void dump()
Dump the joint settings.
const int16_t & getMinAngle(uint8_t joint_id)
Get min angle of the joint given.
Definition: JointController.h:37
Definition: JointController.h:51
Config file for each build environment.
Management class of joints.
Definition: JointController.h:29
Definition: JointController.h:43
Definition: JointController.h:38
Definition: JointController.h:49
Definition: JointController.h:44
Definition: JointController.h:45
Definition: JointController.h:50
bool setHomeAngle(uint8_t joint_id, int16_t angle)
Set home angle of the joint given.
Definition: JointController.h:42
JOINT_INDEX
Definition: JointController.h:32
Definition: JointController.h:47