Librairie pour contrôler un moteur connecté à un contrôleur SDC21XX
Dependencies: CANopen_Node Roboteq_SDC_serie
Dependents: TCP_Server_Example
Fork of SDC21XX_Motor by
SDC21XX_Motor.cpp@1:a677037eca0a, 2016-07-11 (annotated)
- Committer:
- kkoichy
- Date:
- Mon Jul 11 11:02:54 2016 +0000
- Revision:
- 1:a677037eca0a
- Parent:
- 0:1c0bc44980e0
- Child:
- 2:30acd3c5d5da
Added comments and example programm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kkoichy | 0:1c0bc44980e0 | 1 | #include "SDC21XX_Motor.h" |
kkoichy | 0:1c0bc44980e0 | 2 | |
kkoichy | 0:1c0bc44980e0 | 3 | |
kkoichy | 0:1c0bc44980e0 | 4 | namespace mbed { |
kkoichy | 0:1c0bc44980e0 | 5 | |
kkoichy | 1:a677037eca0a | 6 | SDC21XX_Motor::SDC21XX_Motor(uint8_t _node_id, CAN * _can, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution): RB(_node_id, _can), channel(_channel), reductor(_reductor), enc_resolution(_enc_resolution) |
kkoichy | 0:1c0bc44980e0 | 7 | { |
kkoichy | 0:1c0bc44980e0 | 8 | |
kkoichy | 0:1c0bc44980e0 | 9 | } |
kkoichy | 1:a677037eca0a | 10 | |
kkoichy | 1:a677037eca0a | 11 | SDC21XX_Motor::SDC21XX_Motor(Roboteq *_RB, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution): RB(_RB->GetNodeID(), _RB->GetCan()), channel(_channel), reductor(_reductor), enc_resolution(_enc_resolution) |
kkoichy | 1:a677037eca0a | 12 | { |
kkoichy | 1:a677037eca0a | 13 | |
kkoichy | 1:a677037eca0a | 14 | } |
kkoichy | 1:a677037eca0a | 15 | |
kkoichy | 0:1c0bc44980e0 | 16 | void SDC21XX_Motor::GoAngle(int16_t _angle) |
kkoichy | 0:1c0bc44980e0 | 17 | { |
kkoichy | 1:a677037eca0a | 18 | RB.SetPosition(_angle*enc_resolution*reductor/360, channel); |
kkoichy | 0:1c0bc44980e0 | 19 | } |
kkoichy | 0:1c0bc44980e0 | 20 | |
kkoichy | 0:1c0bc44980e0 | 21 | int16_t SDC21XX_Motor::GetAngle() |
kkoichy | 0:1c0bc44980e0 | 22 | { |
kkoichy | 1:a677037eca0a | 23 | return RB.ReadAbsoluteEncoderCount(channel)*360/enc_resolution/reductor; |
kkoichy | 0:1c0bc44980e0 | 24 | } |
kkoichy | 0:1c0bc44980e0 | 25 | |
kkoichy | 0:1c0bc44980e0 | 26 | void SDC21XX_Motor::SetChannel(uint8_t _channel) |
kkoichy | 0:1c0bc44980e0 | 27 | { |
kkoichy | 0:1c0bc44980e0 | 28 | channel = _channel; |
kkoichy | 0:1c0bc44980e0 | 29 | } |
kkoichy | 0:1c0bc44980e0 | 30 | |
kkoichy | 0:1c0bc44980e0 | 31 | uint8_t SDC21XX_Motor::GetChannel(void) |
kkoichy | 0:1c0bc44980e0 | 32 | { |
kkoichy | 0:1c0bc44980e0 | 33 | return channel; |
kkoichy | 0:1c0bc44980e0 | 34 | } |
kkoichy | 0:1c0bc44980e0 | 35 | |
kkoichy | 0:1c0bc44980e0 | 36 | void SDC21XX_Motor::SetReductor(uint32_t _reductor) |
kkoichy | 0:1c0bc44980e0 | 37 | { |
kkoichy | 0:1c0bc44980e0 | 38 | reductor = _reductor; |
kkoichy | 0:1c0bc44980e0 | 39 | } |
kkoichy | 0:1c0bc44980e0 | 40 | |
kkoichy | 0:1c0bc44980e0 | 41 | uint32_t SDC21XX_Motor::GetReductor(void) |
kkoichy | 0:1c0bc44980e0 | 42 | { |
kkoichy | 0:1c0bc44980e0 | 43 | return reductor; |
kkoichy | 0:1c0bc44980e0 | 44 | } |
kkoichy | 0:1c0bc44980e0 | 45 | |
kkoichy | 0:1c0bc44980e0 | 46 | void SDC21XX_Motor::SetNodeID(uint8_t _node_id) |
kkoichy | 0:1c0bc44980e0 | 47 | { |
kkoichy | 0:1c0bc44980e0 | 48 | RB.SetNodeID(_node_id); |
kkoichy | 0:1c0bc44980e0 | 49 | } |
kkoichy | 0:1c0bc44980e0 | 50 | |
kkoichy | 0:1c0bc44980e0 | 51 | uint8_t SDC21XX_Motor::GetNodeID(void) |
kkoichy | 0:1c0bc44980e0 | 52 | { |
kkoichy | 0:1c0bc44980e0 | 53 | return RB.GetNodeID(); |
kkoichy | 0:1c0bc44980e0 | 54 | } |
kkoichy | 0:1c0bc44980e0 | 55 | |
kkoichy | 0:1c0bc44980e0 | 56 | void SDC21XX_Motor::SetCan(CAN * _can) |
kkoichy | 0:1c0bc44980e0 | 57 | { |
kkoichy | 0:1c0bc44980e0 | 58 | RB.SetCan(_can); |
kkoichy | 0:1c0bc44980e0 | 59 | } |
kkoichy | 0:1c0bc44980e0 | 60 | |
kkoichy | 0:1c0bc44980e0 | 61 | CAN* SDC21XX_Motor::GetCan(void) |
kkoichy | 0:1c0bc44980e0 | 62 | { |
kkoichy | 0:1c0bc44980e0 | 63 | return RB.GetCan(); |
kkoichy | 0:1c0bc44980e0 | 64 | } |
kkoichy | 0:1c0bc44980e0 | 65 | |
kkoichy | 0:1c0bc44980e0 | 66 | |
kkoichy | 0:1c0bc44980e0 | 67 | }//end namespace |