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@4:7aaa045734b7, 2016-07-21 (annotated)
- Committer:
- kkoichy
- Date:
- Thu Jul 21 13:11:07 2016 +0000
- Revision:
- 4:7aaa045734b7
- Parent:
- 2:30acd3c5d5da
Commit
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 | 2:30acd3c5d5da | 65 | |
kkoichy | 2:30acd3c5d5da | 66 | void SDC21XX_Motor::SetVelocity(uint16_t _vel) |
kkoichy | 2:30acd3c5d5da | 67 | { |
kkoichy | 2:30acd3c5d5da | 68 | RB.SetVelocity(_vel, channel); |
kkoichy | 2:30acd3c5d5da | 69 | } |
kkoichy | 4:7aaa045734b7 | 70 | |
kkoichy | 2:30acd3c5d5da | 71 | void SDC21XX_Motor::SetAcceleration(long _accel) |
kkoichy | 2:30acd3c5d5da | 72 | { |
kkoichy | 2:30acd3c5d5da | 73 | RB.SetAcceleration(_accel, channel); |
kkoichy | 2:30acd3c5d5da | 74 | } |
kkoichy | 4:7aaa045734b7 | 75 | |
kkoichy | 2:30acd3c5d5da | 76 | void SDC21XX_Motor::SetDeceleration(long _decel) |
kkoichy | 2:30acd3c5d5da | 77 | { |
kkoichy | 2:30acd3c5d5da | 78 | RB.SetDeceleration(_decel, channel); |
kkoichy | 2:30acd3c5d5da | 79 | } |
kkoichy | 4:7aaa045734b7 | 80 | |
kkoichy | 2:30acd3c5d5da | 81 | void SDC21XX_Motor::Setparameters(uint16_t _vel, long _accel, long _decel) |
kkoichy | 2:30acd3c5d5da | 82 | { |
kkoichy | 2:30acd3c5d5da | 83 | RB.SetParameters(_vel, _accel, _decel, channel); |
kkoichy | 2:30acd3c5d5da | 84 | } |
kkoichy | 2:30acd3c5d5da | 85 | |
kkoichy | 4:7aaa045734b7 | 86 | void SDC21XX_Motor::SetRB(Roboteq* _RB) |
kkoichy | 4:7aaa045734b7 | 87 | { |
kkoichy | 4:7aaa045734b7 | 88 | RB = *_RB; |
kkoichy | 4:7aaa045734b7 | 89 | } |
kkoichy | 4:7aaa045734b7 | 90 | Roboteq* SDC21XX_Motor::GetRB(void) |
kkoichy | 4:7aaa045734b7 | 91 | { |
kkoichy | 4:7aaa045734b7 | 92 | return &RB; |
kkoichy | 4:7aaa045734b7 | 93 | } |
kkoichy | 4:7aaa045734b7 | 94 | |
kkoichy | 0:1c0bc44980e0 | 95 | |
kkoichy | 0:1c0bc44980e0 | 96 | |
kkoichy | 0:1c0bc44980e0 | 97 | }//end namespace |