I went ahead and emailed pololu regarding the baby-o and seeing if i cant get it repaired or replaced. The new one is up and running. but I still can’t get the mirror command to work. I might have gotten it by accident but I must have changed something and now I don’t know what to do about it. Right now the code is like this
#define F_CPU 20000000//Baby Orangutan CPU clock
#define BAUD 9600//baud rate for UART
#define MYUBRR 129//(F_CPU/16/BAUD-1)//baud rate variable for UART hardware
#include <pololu/orangutan.h>
#include <avr/io.h>
void USART_Init(unsigned int ubrr){//Initialize USART hardware & settings for Serial Radio
UBRR0H=(unsigned char)(ubrr>>8);//set buad rate
UBRR0L=(unsigned char) ubrr;
UCSR0B=(1<<TXEN0);//enable transmitter
UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop
}
void USART_Trans (unsigned char data){//Transmit a byte of data over USART
while(!(UCSR0A&(1<<UDRE0)));//wait for transmition to complete
UDR0=data;
}
void put(unsigned char servo, unsigned int angle){
//servo is the servo number (typically 0-7)
//angle is the absolute position from 500 to 5500
//Send a Pololu Protocol command
USART_Trans(0x80); //start byte
USART_Trans(0x01); //device id
USART_Trans(0x04); //command number
USART_Trans(servo); //servo number
//Convert the angle data into two 7-bit bytes
USART_Trans(((angle>>7)&0x3f)); //data1
USART_Trans((angle&0x7f)); //data2
}
void servoOff(unsigned char servo){//turns off a servo
//(servo will go limp until next position command)
//servo is the servo number (typically 0-7)
//Send a Pololu Protocol command
USART_Trans(0x80);//start byte
USART_Trans(0x01);//device id
USART_Trans(0x00);//command number
USART_Trans(servo);//servo number
USART_Trans(0x0f);//data1 (turn servo off, keep full range)
}
void servoSetSpeed(unsigned char servo, unsigned char speedcmd){
//servo is the servo number (typically 0-7)
//speed is servo speed (1=slowest, 127=fastest)
//set speed to zero to turn off speed limiting
speedcmd=speedcmd&0x7f;//take only lower 7 bits of the speed
//Send a Pololu Protocol command
USART_Trans(0x80);//start byte
USART_Trans(0x01);//device id
USART_Trans(0x01);//command number
USART_Trans(servo);//servo number
USART_Trans(speedcmd);//data1
}
int main()
{
USART_Init(MYUBRR);
while(1)
{
servoSetSpeed(0,0x00);
servoSetSpeed(1,0x00);
void mirror(unsigned char servo, unsigned char servoMirror, unsigned int angle)
{
put(servo,angle);
put(servoMirror,(5500-angle+500));
}
delay(1000);
put(0, 1500);
put(1, 1500);
delay(1000);
put(0, 3000);
put(1, 3000);
delay(1000);
put(0, 4450);
put(1, 4450);
delay(1000);
put(0, 3000);
put(1, 3000);
return(0);
}
}
Later I’m going to comment out the return(0); so the code runs in an infinite loop so that I can see how long the battery will last under constant use. (I have a requirement of 45minutes to 1 hour of operation) I wont be running under load, and I will be running four servos with the same command.
How should I be using the mirror command?
like this:
oid mirror(unsigned char servo, unsigned char servoMirror, unsigned int angle)
{
put(0x00,1500);
put(0x01,(5500-1500+500));
}
or like this:
oid mirror(unsigned char servo, unsigned char servoMirror, unsigned int angle)
{
put(servo,angle);
put(servoMirror,(5500-angle+500));
put(0, 1500);
put(1, 1500);
}