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 Pierre David

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?

UserRevisionLine numberNew 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 1:a677037eca0a 13 */
kkoichy 1:a677037eca0a 14 /**************************************************/
kkoichy 1:a677037eca0a 15
kkoichy 1:a677037eca0a 16 /**************************************************/
kkoichy 1:a677037eca0a 17 /* Example programm
kkoichy 1:a677037eca0a 18 #include "mbed.h"
kkoichy 1:a677037eca0a 19 #include "SDC21XX_Motor.h"
kkoichy 1:a677037eca0a 20
kkoichy 1:a677037eca0a 21 CAN can(p30, p29);
kkoichy 1:a677037eca0a 22 Roboteq Robot_Moteur1(4, &can);
kkoichy 1:a677037eca0a 23 SDC21XX_Motor moteur1(&Robot_moteur, 1, 70, 1000);
kkoichy 1:a677037eca0a 24 SDC21XX_Motor moteur1(&Robot_moteur, 2, 50, 512);
kkoichy 1:a677037eca0a 25
kkoichy 1:a677037eca0a 26
kkoichy 1:a677037eca0a 27 int main(void)
kkoichy 1:a677037eca0a 28 {
kkoichy 1:a677037eca0a 29
kkoichy 1:a677037eca0a 30 for(;;)
kkoichy 1:a677037eca0a 31 {
kkoichy 1:a677037eca0a 32 wait(3.0);
kkoichy 1:a677037eca0a 33 moteur1.GoAngle(1000);
kkoichy 1:a677037eca0a 34 moteur2.GoAngle(-1000);
kkoichy 1:a677037eca0a 35 wait(3.0);
kkoichy 1:a677037eca0a 36 moteur1.GoAngle(-1000);
kkoichy 1:a677037eca0a 37 moteur2.GoAngle(1000);
kkoichy 1:a677037eca0a 38 }
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 0:1c0bc44980e0 47 #ifndef SDC21XX_MOTOR_H
kkoichy 0:1c0bc44980e0 48 #define SDC21XX_MOTOR_H
kkoichy 0:1c0bc44980e0 49
kkoichy 0:1c0bc44980e0 50 #include "mbed.h"
kkoichy 0:1c0bc44980e0 51 #include "Roboteq.h"
kkoichy 0:1c0bc44980e0 52
kkoichy 0:1c0bc44980e0 53 namespace mbed {
kkoichy 0:1c0bc44980e0 54
kkoichy 0:1c0bc44980e0 55 class SDC21XX_Motor {
kkoichy 0:1c0bc44980e0 56
kkoichy 0:1c0bc44980e0 57 public :
kkoichy 0:1c0bc44980e0 58
kkoichy 1:a677037eca0a 59 SDC21XX_Motor(uint8_t _node_id, CAN * _can, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution);
kkoichy 1:a677037eca0a 60 SDC21XX_Motor(Roboteq *_RB, uint8_t _channel, uint32_t _reductor, uint32_t _enc_resolution);
kkoichy 0:1c0bc44980e0 61 void GoAngle(int16_t _angle);
kkoichy 0:1c0bc44980e0 62 int16_t GetAngle();
kkoichy 0:1c0bc44980e0 63 void SetChannel(uint8_t _channel);
kkoichy 0:1c0bc44980e0 64 uint8_t GetChannel(void);
kkoichy 0:1c0bc44980e0 65 void SetReductor(uint32_t _reductor);
kkoichy 0:1c0bc44980e0 66 uint32_t GetReductor(void);
kkoichy 0:1c0bc44980e0 67 void SetNodeID(uint8_t _node_id);
kkoichy 0:1c0bc44980e0 68 uint8_t GetNodeID(void);
kkoichy 0:1c0bc44980e0 69 void SetCan(CAN * _can);
kkoichy 0:1c0bc44980e0 70 CAN* GetCan(void);
kkoichy 0:1c0bc44980e0 71
kkoichy 0:1c0bc44980e0 72 private :
kkoichy 0:1c0bc44980e0 73
kkoichy 0:1c0bc44980e0 74 protected :
kkoichy 0:1c0bc44980e0 75
kkoichy 0:1c0bc44980e0 76 Roboteq RB;
kkoichy 0:1c0bc44980e0 77 uint8_t channel;
kkoichy 0:1c0bc44980e0 78 uint32_t reductor;
kkoichy 1:a677037eca0a 79 uint32_t enc_resolution;
kkoichy 0:1c0bc44980e0 80
kkoichy 0:1c0bc44980e0 81
kkoichy 0:1c0bc44980e0 82 };//end class
kkoichy 0:1c0bc44980e0 83
kkoichy 0:1c0bc44980e0 84
kkoichy 0:1c0bc44980e0 85
kkoichy 0:1c0bc44980e0 86
kkoichy 0:1c0bc44980e0 87 }//end namespace
kkoichy 0:1c0bc44980e0 88
kkoichy 0:1c0bc44980e0 89 #endif