Buongiorno a tutti
volevo chiedervi un consiglio sul conteggio degli "step" eseguiti da un motore nema17.
In un progetto simile si utilizza un motere DC dotato di encoder magnetico, ma sul mio progetto utilizzando un motore passo-passo dovrei riuscire fare a meno dell'encoder poiché dovrebbe riuscire a non perdere passi.
Il mio progetto di base utilizza il progetto YABR quindi la frequenza degli impulsi è data dal timer configurato a codice OCR2A = 39 (ogni 20us), il singolo passo del nema17 è 1,8° avendo fissato il microstepping sul drv4988 ( MS1=L/MS2=H/MS3=L => 1/4 ), lo step per impulso è 1,8°/4 corretto?
La mia confusione nasce dal fatto che non capisco a pieno il codice YABR utilizzato nella funzione ridefinita per interrupt.
loop{
throttle_left_motor = Valore definito dal PID controller
}
ISR(TIMER2_COMPA_vect){
//Left motor pulse calculations
throttle_counter_left_motor ++; //Increase the throttle_counter_left_motor variable by 1 every time this routine is executed
if(throttle_counter_left_motor > throttle_left_motor_memory){ //If the number of loops is larger then the throttle_left_motor_memory variable
throttle_counter_left_motor = 0; //Reset the throttle_counter_left_motor variable
throttle_left_motor_memory = throttle_left_motor; //Load the next throttle_left_motor variable
if(throttle_left_motor_memory < 0){ //If the throttle_left_motor_memory is negative
//PORTD &= 0b11110111;
PORTH &= 0b11111100; //_BV(PH3); //Set output 3 low to reverse the direction of the stepper controller
throttle_left_motor_memory *= -1; //Invert the throttle_left_motor_memory variable
}
else
//PORTD |= 0b00001000;
PORTH |= 0b00000011; //~_BV(PH3); //Set output 3 high for a forward direction of the stepper motor
}
else if(throttle_counter_left_motor == 1)
PORTH |= 0b00001000; //_BV(PH4); //Set output 2 high to create a pulse for the stepper controller
else if(throttle_counter_left_motor == 2)
PORTH &= 0b11110111; //~_BV(PH4); //Set output 2 low because the pulse only has to last for 20us
//....parte di codice uguale per controllo motore destro
La domanda è la seguente: per conteggiare i tick (e pubblicarli come messaggio ROS) basta semplicemente verificare la condizione
else if(throttle_counter_left_motor == 1)
mentre la direzione viene determinata da quest'altra condizione
if(throttle_left_motor_memory < 0)
Spero di essere stato chiaro nella domanda??
grazie ![]()