Hello all. I posted previously in the Robot Tech forum regarding a school project I’m working on. The thread is here if you’re interested.
Basically I need to make two resistance bend sensors linearly control two pairs of servos. I’m using the Pololu Baby-Orangutan B-168 and the Micro serial servo controller. I have everything wired up for the most part but I haven’t been able to figure out what command lines i need to use to declare the servo controller within the main body of the code. Below is the modified motor control sample code that I tried to incorporate servo commands into. I only have two servos declared for testing purposes. I know the code is wrong 100 different ways but it’s a start and I was hoping someone might be able to help.
Ultimately I’d want the servos in the first four ports on the servo controller and the serial (SIN) port would go to the PD1 port on the Baby-O. How do I declare that and do I need some other .h files other than the included orangutan one in all the sample codes?
#include <servotest/orangutan.h>
unsigned long prevMillis = 0;
unsigned char left, right;
left = servo_define(_SFR_IO_ADDR(DDRD), _SFR_IO_ADDR(PORTD), 6);
right = servo_define(_SFR_IO_ADDR(DDRD), _SFR_IO_ADDR(PORTD), 7);
int main()
{
servo_active(left); // Turn on left servo
servo_active(right); // Turn on right servo
servo_set(left, 1000); // Center left servo
servo_set(right, 1000); // Set right servo to max
while(1)
{
int bleft = analogRead(0);
int bright = analogRead(1);
int motorSpeed1 = bleft/2-256; // turn pot reading into number between -256 and 255
int motorSpeed2 = bright/2-256;
if(motorSpeed1 == -256)
motorSpeed1 = -255; // 256 is out of range
servo_set(left, motorSpeed1);
if(motorSpeed2 == -256)
motorSpeed2 = -255; // 256 is out of range
servo_set(right, motorSpeed2);
}
}
I understand that here the servos are declared in the PD6 and 7 ports, but do I declare the servo controller ports similarly?
Thanks in advance for any help.