====== POLOLU TReX Jr ======
===== Introduction =====
POLOLU [[http://www.pololu.com/docs/0J5|TreX Jr]] est un double contrôleur de moteur à courant continu. Il peut piloter 2 moteurs bidirectionnels et un moteur unidirectionnel via 3 interfaces indépendantes :
* contrôle radio (RC)
* tension analogique
* liaison série asynchrone (RS-232 ou TTL)
Il est basé sur 2 pont H [[http://www.pololu.com/file/0J54/MC33887.pdf|MC33887]] acceptant des courants de 5A continu et jusqu'à 7.8A en pointe. La tension d'utilisation est comprise entre 5V et 28V.
===== Commande par liaison série =====
Le controleur peut recevoir différentes [[http://www.pololu.com/file/0J12/TReXJr_Commands_v1.2.pdf|commandes]] selon 2 types de trames :
* protocole pololu (pour assurer la compatibilité avec les autres produits pololu)
* protocole compact
==== protocole compact ====
=== Commande « set motor » ===
Cette commande indique pour chaque moteur le sens et la vitesse de rotation
^Commande ^MOTEUR 1 ^MOTEUR 2^
|FREIN |0xC0 |0xC8|
|AVANT |0xC1 |0xC9|
|ARRIERE |0xC2 |0xCA|
|FREIN |0xC3 |0xCB|
Il faut envoyer le code de la commande suivit de la vitesse (entre 0 et 127).
Exemple pour le moteur 1 en sens inverse avec une vitesse de 50, il faut envoyer 0xC2, 0x32
/*
* usart.c
*
* Created on: May 12, 2012
* Author: ldo
*/
#include
void
usart_initialise(void)
{
// set baud rate : 19200 bps
UBRR0H = 0;
UBRR0L = 51;
// enable receiver and transmiter
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
// set frame format : asynchronous mode 8 data, 1 stop bit, no parity
UCSR0C = (0 << UMSEL01) | (0 << UMSEL00) | (0 << UPM01) | (0 << UPM00)
| (0 << USBS0) | (1 << UCSZ01) | (1 << UCSZ00);
}
// transmit a char
void
usart_transmit(unsigned char data)
{
// wait for empty transmit buffer
while (!(UCSR0A & (1 << UDRE0)))
;
// put data info buffer, sends the data
UDR0 = data;
}
/*
* trex_jr.h
*
* Created on: 8 avr. 2013
* Author: ldo
*/
#ifndef TREX_JR_H_
#define TREX_JR_H_
#define MOTOR_1 0
#define MOTOR_2 1
#define SET_MOTOR 0xC0
#define BRAKE 0
#define REVERSE 1
#define FORWARD 2
void
trex_jr_initialise(void);
void
trex_jr_set_motor(char motor, char direction, char speed);
#endif /* TREX_JR_H_ */
/*
* trex_jr.c
*
* Created on: 8 avr. 2013
* Author: ldo
*/
#include "usart.h"
#include "trex_jr.h"
void
trex_jr_initialise(void)
{
/* usart initialise : baud rate 19200 bps, no error detection, one stop bit */
usart_initialise();
}
/* set motor
* motor (1 or 2)
* direction (brake, reverse or forward)
* speed max 127
* */
void
trex_jr_set_motor(char motor, char direction, char speed)
{
char command = SET_MOTOR;
command += motor * 8; // select motor
command += direction; // select direction
usart_transmit(command);
usart_transmit(speed);
}
/*
* main.c
*
* Created on: 8 avr. 2013
* Author: ldo
*/
#include
#include
#include "trex_jr.h"
ISR(TIMER1_OVF_vect)
{
trex_jr_set_motor(MOTOR_1, FORWARD, 10);
TCNT1 = 0;
TIFR1 |= (1 << TOV1);
}
void
init_port(void)
{
DDRD = 0x02;
PORTD = 0;
}
void
init_timer1(void)
{
TCCR1A = 0;
TCCR1B = (1 << CS11) | (1 << CS10); // prescaler 64
TCCR1C = 0;
TCNT1 = 0;
TIMSK1 = (1 << TOIE1); // overflow interrupt enable
}
int
main(void)
{
init_port();
trex_jr_initialise();
init_timer1();
SREG = (1 << SREG_I); /* The Global Interrupt Enable bit must be set for the interrupts to be enabled */
while (1)
{
}
}