Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Objective

The objective of this tutorial is to reproduce the behavior of a mechanism for which we want to limit
the movement using a limit switch. Limit switches are often use to indicate that a mechanism has
reached a certain position, or to automatically stop the motor that moves a mechanism that has
reached the limit of its reach. In simpler terms: we want the motor to stop before is breaks
everything!

...

Objectif

L’objectif de ce tutoriel est de reproduire le comportement d’un mécanisme dont on souhaite restreindre le mouvement à l’aide d’un interrupteur de position. Ceux-ci sont typiquement utilisés pour indiquer qu’un mécanisme a atteint une certaine position, ou pour automatiquement arrêter le mouvement d’un moteur lorsque le mécanisme a atteint la limite de sa portée. En gros: on veut que le moteur arrête avant de tout casser !

Schéma électrique et présentation complète

View file
nameCrcDuino_Tuto1_PlansElectriques_20201118.pdf

Code

Download the Arduino IDE .ino fileTéléchargez le code de démonstration:

View file
nameTutoriel01_LimitSwitch_20201118.ino

This is a transcript of the codeQui est ici retranscrit:

Code Block
languagecpp
//**************************************************************************************************************************
// CrcDuino TutorialTutoriel 1 - LimitingMoteur aavec motor using a limit switch« limit switch »
//NOTE: Continuous Servos often have a Les servos à rotation continue ont souvent une vis de calibration screwsur onle their sidecôté.
//      IfSi you'revous sendingenvoyez aun "0" commandau toservo the servo, bu it still runs, turn the screw until the motor stopset celui-ci tourne encore, ajustez la vis jusqu'à ce que le moteur s'arrête.
//      ThisCette calibratescalibration thepermet neutral signal of the servo, telling it "Ok buddy, the signal you're receiving corresponds to
//      a stop command ".
d'informer le servo de la position neutre: « Ok c'est bon, bouge plus ! »
//**************************************************************************************************************************
#include <CrcLib.h>  //CrcLib programObligatoire
requirement

//Rename IOs with a meaningful name (good practice) C'est pratique d'avoir un nom pour chaque port de contrôle
#define SERVO_CONT_1 CRC_PWM_5
#define BTN_RUNAVANCE CRC_DIG_1
#define LS1_SERVO_CONT_1 CRC_DIG_2

//**************************************************************************************************************************
void setup() {
  // putMettez yourvotre setupcode coded'initialisation hereici, to run once at the beginning:il s'exécutera une seule fois, au début du programme
  CrcLib::Initialize(); //Sets upInitialise thele CrcDuinoCRCduino
  
  CrcLib::InitializePwmOutput(SERVO_CONT_1); //Sets Configure upla thesortie motordu outputmoteur
  CrcLib::SetDigitalPinMode(BTN_RUNAVANCE, INPUT); //Sets upConfigure thele digitalbouton portde asla an« limit Inputswitch »
  CrcLib::SetDigitalPinMode(LS1_SERVO_CONT_1, INPUT);
}
//**************************************************************************************************************************
void loop() {
  // putMettez yourici mainle code here, to run repeatedly: de la boucle principale, qui s'exécutera à l'infini
  CrcLib::Update(); //Refreshes the CrcDuino Tâches de routine du CRCduino

  if( CrcLib::GetDigitalInput(BTN_RUNAVANCE) == LOW )  //When Quand thele buttonbouton isest pressedappuyé (GND isest connectedconnecté to the inputà l'entrée, sodonc CrcLib::GetDigitalInput() returnsretourne LOW)
  {
    if( CrcLib::GetDigitalInput(LS1_SERVO_CONT_1) == HIGH )  //But Mais onlyseulement ifsi thela limit« limit switchswitch » isn'est notpas pressedenfoncée (5V applied to the inputà l'entrée, sodonc CrcLib::GetDigitalInput() returnsretourne HIGH)
    {
      CrcLib::SetPwmOutput(SERVO_CONT_1, 127);  //127=Full speed 127 -> Pleine vitesse
    }
    else  //when Quand thela limit« limit switchswitch » isest pressedenfoncée...
    {
      CrcLib::SetPwmOutput(SERVO_CONT_1, 0);  //0=stop 0 -> On arrête
    }
  }
  else  //when Quand thele buttonbouton isn'est notpas pressedenfoncé...
  {
    CrcLib::SetPwmOutput(SERVO_CONT_1, 0);  //0=stop 0 -> On arrête
  }
}
//**************************************************************************************************************************