eBoard ①⑧⑨
Written for SIA 2017/2018
eagle_AX12Servo.h
Go to the documentation of this file.
1 #ifndef EAGLE_EBOARD_HELPLIB_AX12SERVO
2  #define EAGLE_EBOARD_HELPLIB_AX12SERVO
3 
12 //=====================================================================================================================================================
13 // AX12Servo
14 //=====================================================================================================================================================
15 
16  //-------------------------------------------------------------------------------------------------------------------------------------------------
17  // cheat :D
18  //-------------------------------------------------------------------------------------------------------------------------------------------------
19 
21  struct DynamixelBoard;
23 
24  //-------------------------------------------------------------------------------------------------------------------------------------------------
25  // class
26  //-------------------------------------------------------------------------------------------------------------------------------------------------
54  struct AX12Servo {
59  AX12Servo(void);
66  AX12Servo(DynamixelBoard &dBoard, optVAL_t servoID); //if borders => setPosLimit
67 
69 
70  #if EBOARD_USE_UTILITY > 0x0
71 
78  inline void setID(optVAL_t newID);
86  inline void changeMotorID(optVAL_t newID); //this should change the hardwareaddress...
92  inline void setPositionMode(void);
98  inline void setSpeedMode(void);
104  inline void setSpeed(optVAL_t);
106  inline void ledOff(void);
108  inline void ledOn(void);
110  inline void setTorque(uint16_t);
111  #endif
112 
120  void setPosition(int pos, int speed=0x3FF);
128  inline void storePosition(int pos, int speed = 0x3FF);
134  inline optVAL_t getPosition(void);
142  inline bool isMoving(void);
155 
156  //bool posMode; //we don't care wich mode we are in ^^
157 
160  private:
162  int actPos;
164  int actSpe;
165 
166  }; //shield //set limits auto register for begin
167 
169 
170  //-------------------------------------------------------------------------------------------------------------------------------------------------
171  // definitions
172  //-------------------------------------------------------------------------------------------------------------------------------------------------
173 
174  AX12Servo::AX12Servo(void) {}
175 
176  #if EBOARD_USE_UTILITY > 0x0
177  void AX12Servo::setID(optVAL_t newID) {this->id = newID;_servoHandler.SetServoLimit(this->id,_servoHandler.upperLimit_temp);}
178  void AX12Servo::changeMotorID(optVAL_t newID) {this->id = newID; _servoHandler.SetID(this->id, newID);} //this -should- *does now* change the hardwareaddress...
179  //IF needed: _servoHandler.setID(this->id, newID);
180  void AX12Servo::setPositionMode(void) {}
181  void AX12Servo::setSpeedMode(void) {}
182  void AX12Servo::setSpeed(optVAL_t) {} //i won't use the rotate functions...
183  void AX12Servo::ledOff(void) {} //noone needs the AX12-Servo LED
184  void AX12Servo::ledOn(void) {} //really.... noone ^^
185  void AX12Servo::setTorque(uint16_t) {} //which damn register? xD
186  #endif
187 
188  void AX12Servo::setPosition(int pos, int speed) {
189  #if EBOARD_CLAMP > 0x0
190  if(pos>1023 || speed > 1023) return;
191  this->actPos=pos; this->storedPos=pos; this->storedSpe = speed;
192  speed = speed*600/1023 - 300;
193  pos = pos *600/1023 - 300;
194  #else
195  if(pos>300 || speed > 300) return;
196  this->actPos=pos; this->storedPos=pos; this->storedSpe = speed;
197  #endif
198  if(speed != actSpe){ _servoHandler.setVelocity(speed); this->actSpe=speed;}
199  _servoHandler.write(this->id,pos);
200  }
202  return this->actPos; //when moving... false value;
203  }
204  bool AX12Servo::isMoving(void) {return false;} //we don't know^^
206 #endif
int actPos
stores the actual pos or move-to pos of the AX12Servo
This is the AX12Servo ghost struct :D.
void storePosition(int pos, int speed=0x3FF)
This saves the Servo Position.
int actSpe
stores the actual 'would use speed' of the AX12Servo
optVAL_t getPosition(void)
This "kind of" returns the Servo-Position.
void SetServoLimit(int ID, int upperLimit)
(probably) set the posLimit for only one servo (will be overwritten by write() => writePos()) ...
void setVelocity(int velocity)
Sets the default speed of servos.
bool isMoving(void)
Use this if you wan't to have a nice way of writing false.
int storedPos
stores the position the Servo should go to DynamixelBoard::action()
optVAL_t id
stores the id of the AX12Servo obejct
void SetID(int ID, int newID)
change the ID of a special Servo
int storedSpe
stores the Speed of the Servo DynamixelBoard::action()
This is the DynamixelBoard ghost struct :D.
int upperLimit_temp
stores the posLimit value send with write()
DynamixelBoard * _conBoard
void write(int ID, int Pos)
Moves a Servo to a certain position.
AX12Servo(void)
The constructor.
void setPosition(int pos, int speed=0x3FF)
This moves the Servo to the new position.
DynamixelBoard dBoard(board)
the dBoard object
ServoCds55 _servoHandler
this is the "to_use" instance of ServoCds55
int optVAL_t
Definition: eBoard.h:137