Adafruit Motor Shield V2-Librairie

De MCHobby - Wiki
Révision datée du 6 janvier 2014 à 12:22 par Admin (discussion | contributions) (Page créée avec « {{Adafruit Motor Shield V2-NAV}} == Classe Adafruit_MotorShield == {{ADFImage|Adafruit Motor Shield V2-Lib-01.jpg|480px}} The Adafruit_MotorShield class represents a motor... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Classe Adafruit_MotorShield

Adafruit Motor Shield V2-Lib-01.jpg
Crédit: AdaFruit Industries www.adafruit.com

The Adafruit_MotorShield class represents a motor shield and must be instantiated before any DCMotors or StepperMotors can be used. You will need to declare one Adafruit_MotorShield for each shield in your system.

Adafruit_MotorShield(addr)

Adafruit_MotorShield(uint8_t addr = 0x60);

The constructor takes one optional parameter to specify the i2c address of the shield. The default address of the constructor (0x60) matches the default address of the boards as shipped. If you have more than one shield in your system, each shield must have a unique address.

begin( freq=1600 )

void begin(uint16_t freq = 1600);

begin() must be called in setup() to initialize the shield. An optional frequency parameter can be used to specify something other than the default maximum: 1.6KHz PWM frequency.

getMotor(n)

Adafruit_DCMotor *getMotor(uint8_t n);

This function returns one of 4 pre-defined DC motor objects controlled by the shield. The parameter specifies the associated motor channel: 1-4.

getStepper(steps, n)

Adafruit_StepperMotor *getStepper(uint16_t steps, uint8_t n);

This function returns one of 2 pre-defined stepper motor objects controlled by the shield. The first parameter specifies the number of steps per revolution. The second parameter specifies the associated stepper channel: 1-2.

setPWM( pin, val)

void setPWM(uint8_t pin, uint16_t val);

These are low-level functions to control pins on the on-board PWM driver chip. These functions are intended for internal use only.

setPin(pin, val)

void setPin(uint8_t pin, boolean val);

These are low-level functions to control pins on the on-board PWM driver chip. These functions are intended for internal use only.

Classe Adafruit_DCMotor

Adafruit Motor Shield V2-Lib-02.jpg
Crédit: AdaFruit Industries www.adafruit.com

The Adafruit_DCMotor class represents a DC motor attached to the shield. You must declare an Adafruit_DCMotor for each motor in your system.

Adafruit_DCMotor()

The constructor takes no arguments. The motor object is typically initialized by assigning a motor object retrieved from the shield class as below:

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
     
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

run( direction )

void run(uint8_t direction);

The run() function controls the motor state. The parameter can have one of 3 values:

  • FORWARD - Rotate in a forward direction
  • REVERSE - Rotate in the reverse direction
  • RELEASE - Stop rotation

Note that the "FORWARD" and "REVERSE" directions are arbitrary. If they do not match the actual direction of your vehicle or robot, simple swap the motor leads.

Also note that "RELEASE" simply cuts power to the motor. It does not apply any braking.

setSpeed(speed)

void setSpeed(uint8_t speed);

The setSpeed() function controls the power level delivered to the motor. The speed parameter is a value between 0 and 255.

Note that setSpeed just controls the power delivered to the motor. The actual speed of the motor will depend on several factors, including: The motor, the power supply and the load.

Classe Adafruit_DCMotor

Adafruit Motor Shield V2-Lib-03.jpg
Crédit: AdaFruit Industries www.adafruit.com

The Adafruit_StepperMotor class represents a stepper motor attached to the shield. You must declare an Adafruit_StepperMotor for each stepper motor in your system.

Adafruit_StepperMotor()

Adafruit_StepperMotor(void);

The constructor takes no arguments. The stepper motor is typically initialized by assigning a stepper object retrieved from the shield as below:

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
     
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

step( steps, dir, style = SINGLE )

void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);

The step() function controls stepper motion.

  • The first parameter specifies how many steps to move.
  • The second parameter specifies the direction: FORWARD or BACKWARD
  • The last parameter specifies the stepping style: SINGLE, DOUBLE, INTERLEAVED or MICROSTEP

The ste() function is synchronous and does not return until all steps are complete. When complete the motor remains powered to apply "holding torque" to maintain position.

setSpeed(speed)

void setSpeed(uint16_t);

The setSpeed() function controls the speed of the stepper motor rotation. Speed is specified in RPM.

onestep( dir, style)

uint8_t onestep(uint8_t dir, uint8_t style);

The oneStep() function is a low-level internal function called by step(). But it can be useful to call on its own to implement more advanced functions such as acceleration or coordinating simultaneous movement of multiple stepper motors. The direction and style parameters are the same as for step(), but onestep() steps exactly once.

Note: Calling step() with a step count of 1 is not the same as calling onestep(). The step function has a delay based on the speed set in setSpeed(). onestep() has no delay.

release()

void release(void);

The release() function removes all power from the motor. Call this function to reduce power requirements if holding torque is not required to maintain position.


Source: Adafruit Motor Shield V2 for Arduino créé par LadyAda pour AdaFruit Industries. Crédit [www.adafruit.com AdaFruit Industries]

Traduit par Meurisse D. pour MCHobby.be

Nos remerciements à Mr Pierre M. pour ses suggestions de correction.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.