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.h@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 | 1:a677037eca0a | 1 | /**************************************************/ |
kkoichy | 1:a677037eca0a | 2 | /* SDC21XX_Motor class : |
kkoichy | 1:a677037eca0a | 3 | - Contains : RB, a Roboteq instance used to communicate with the SDC21XX controller |
kkoichy | 1:a677037eca0a | 4 | channel, range from 1 to 2, indicates the channel to which the motor is physically connected |
kkoichy | 1:a677037eca0a | 5 | reductor, ratio to use to determine the right angle of the motor |
kkoichy | 1:a677037eca0a | 6 | enc_resolution, number of ticks from the encoder per rotation of the motor, before the reductor |
kkoichy | 1:a677037eca0a | 7 | |
kkoichy | 1:a677037eca0a | 8 | - Methods : 1 constructor, containing a node identifier, a CAN pointer, the channel of the motor, the reductor and the encoder resolution, |
kkoichy | 1:a677037eca0a | 9 | the Roboteq object is instanciated during the instanciation of the SDC21XX_motor object |
kkoichy | 1:a677037eca0a | 10 | 1 constructor, using a pointer to a Roboteq object instead of node identifier and CAN pointer |
kkoichy | 1:a677037eca0a | 11 | Getters and setters for every variable |
kkoichy | 1:a677037eca0a | 12 | Go- and GetAngle, to move the selected axis, using reductor and encoder resolution |
kkoichy | 2:30acd3c5d5da | 13 | SetVelocity, SetAcceleration, SetDeceleration, SetParameters, servant à régler la vitesse de rotation, l'accéleration et la déceleration |
kkoichy | 1:a677037eca0a | 14 | */ |
kkoichy | 1:a677037eca0a | 15 | /**************************************************/ |
kkoichy | 1:a677037eca0a | 16 | |
kkoichy | 1:a677037eca0a | 17 | /**************************************************/ |
kkoichy | 1:a677037eca0a | 18 | /* Example programm |
kkoichy | 1:a677037eca0a | 19 | #include "mbed.h" |
kkoichy | 1:a677037eca0a | 20 | #include "SDC21XX_Motor.h" |
kkoichy | 1:a677037eca0a | 21 | |
kkoichy | 1:a677037eca0a | 22 | CAN can(p30, p29); |
kkoichy | 1:a677037eca0a | 23 | Roboteq Robot_Moteur1(4, &can); |
kkoichy | 1:a677037eca0a | 24 | SDC21XX_Motor moteur1(&Robot_moteur, 1, 70, 1000); |
kkoichy | 1:a677037eca0a | 25 | SDC21XX_Motor moteur1(&Robot_moteur, 2, 50, 512); |
kkoichy | 1:a677037eca0a | 26 | |
kkoichy | 1:a677037eca0a | 27 | |
kkoichy | 1:a677037eca0a | 28 | int main(void) |
kkoichy | 1:a677037eca0a | 29 | { |
kkoichy | 1:a677037eca0a | 30 | |
kkoichy | 1:a677037eca0a | 31 | for(;;) |
kkoichy | 1:a677037eca0a | 32 | { |
kkoichy | 1:a677037eca0a | 33 | wait(3.0); |
kkoichy | 1:a677037eca0a | 34 | moteur1.GoAngle(1000); |
kkoichy | 1:a677037eca0a | 35 | moteur2.GoAngle(-1000); |
kkoichy | 1:a677037eca0a | 36 | wait(3.0); |
kkoichy | 1:a677037eca0a | 37 | moteur1.GoAngle(-1000); |
kkoichy | 1:a677037eca0a | 38 | moteur2.GoAngle(1000); |
kkoichy | 1:a677037eca0a | 39 | } |
kkoichy | 1:a677037eca0a | 40 | } |
kkoichy | 1:a677037eca0a | 41 | |
kkoichy | 1:a677037eca0a | 42 | |
kkoichy | 1:a677037eca0a | 43 | /**************************************************/ |
kkoichy | 1:a677037eca0a | 44 | |
kkoichy | 1:a677037eca0a | 45 | |
kkoichy | 1:a677037eca0a | 46 | |
kkoichy | 1:a677037eca0a | 47 | |
kkoichy | 0:1c0bc44980e0 | 48 | #ifndef SDC21XX_MOTOR_H |
kkoichy | 0:1c0bc44980e0 | 49 | #define SDC21XX_MOTOR_H |
kkoichy | 0:1c0bc44980e0 | 50 | |
kkoichy | 0:1c0bc44980e0 | 51 | #include "mbed.h" |
kkoichy | 0:1c0bc44980e0 | 52 | #include "Roboteq.h" |
kkoichy | 0:1c0bc44980e0 | 53 | |
kkoichy | 0:1c0bc44980e0 | 54 | namespace mbed { |
kkoichy | 0:1c0bc44980e0 | 55 | |
kkoichy | 0:1c0bc44980e0 | 56 | class SDC21XX_Motor { |
kkoichy | 0:1c0bc44980e0 | 57 | |
kkoichy | 0:1c0bc44980e0 | 58 | public : |
kkoichy | 0:1c0bc44980e0 | 59 | |
kkoichy | 1:a677037eca0a | 60 | SDC21XX_Motor(uint8_t _node_id, CAN * _can, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution); |
kkoichy | 1:a677037eca0a | 61 | SDC21XX_Motor(Roboteq *_RB, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution); |
kkoichy | 0:1c0bc44980e0 | 62 | void GoAngle(int16_t _angle); |
kkoichy | 0:1c0bc44980e0 | 63 | int16_t GetAngle(); |
kkoichy | 0:1c0bc44980e0 | 64 | void SetChannel(uint8_t _channel); |
kkoichy | 0:1c0bc44980e0 | 65 | uint8_t GetChannel(void); |
kkoichy | 0:1c0bc44980e0 | 66 | void SetReductor(uint32_t _reductor); |
kkoichy | 0:1c0bc44980e0 | 67 | uint32_t GetReductor(void); |
kkoichy | 0:1c0bc44980e0 | 68 | void SetNodeID(uint8_t _node_id); |
kkoichy | 0:1c0bc44980e0 | 69 | uint8_t GetNodeID(void); |
kkoichy | 0:1c0bc44980e0 | 70 | void SetCan(CAN * _can); |
kkoichy | 0:1c0bc44980e0 | 71 | CAN* GetCan(void); |
kkoichy | 2:30acd3c5d5da | 72 | void SetVelocity(uint16_t _vel); |
kkoichy | 2:30acd3c5d5da | 73 | void SetAcceleration(long _accel); |
kkoichy | 2:30acd3c5d5da | 74 | void SetDeceleration(long _decel); |
kkoichy | 2:30acd3c5d5da | 75 | void Setparameters(uint16_t _vel, long _accel, long _decel); |
kkoichy | 4:7aaa045734b7 | 76 | void SetRB (Roboteq* _RB); |
kkoichy | 4:7aaa045734b7 | 77 | Roboteq* GetRB(void); |
kkoichy | 4:7aaa045734b7 | 78 | |
kkoichy | 0:1c0bc44980e0 | 79 | |
kkoichy | 0:1c0bc44980e0 | 80 | private : |
kkoichy | 0:1c0bc44980e0 | 81 | |
kkoichy | 0:1c0bc44980e0 | 82 | protected : |
kkoichy | 0:1c0bc44980e0 | 83 | |
kkoichy | 0:1c0bc44980e0 | 84 | Roboteq RB; |
kkoichy | 0:1c0bc44980e0 | 85 | uint8_t channel; |
kkoichy | 0:1c0bc44980e0 | 86 | uint32_t reductor; |
kkoichy | 1:a677037eca0a | 87 | uint32_t enc_resolution; |
kkoichy | 0:1c0bc44980e0 | 88 | |
kkoichy | 0:1c0bc44980e0 | 89 | |
kkoichy | 0:1c0bc44980e0 | 90 | };//end class |
kkoichy | 0:1c0bc44980e0 | 91 | |
kkoichy | 0:1c0bc44980e0 | 92 | |
kkoichy | 0:1c0bc44980e0 | 93 | |
kkoichy | 0:1c0bc44980e0 | 94 | |
kkoichy | 0:1c0bc44980e0 | 95 | }//end namespace |
kkoichy | 0:1c0bc44980e0 | 96 | |
kkoichy | 0:1c0bc44980e0 | 97 | #endif |