In Thursday’s class we spent the remaining time just debugging my Godzilla rig, so sorry for anyone else that needed debug advice. Unfortunately that was only problem #1.
Problem #2: servo motor control
I tried using the ‘pulse’ code from ITP. I wired and coded the servo signal (analog) to correspond to potentiometer readout (analog). Unfortunately, all I was able to get out of this was speed control and not position control.
So I tried the servo library as advised (for anyone trying, the install dir is hareware\libraries, not what it says on that page). It specifically says I can set servo position with a 0~180 (degree) numerical input into a library-defined servo.write function, but I still get speed control and no position control. An input of 94 makes the servo rotate in one direction til it pins itself, 95 holds it in place, and 96 makes it rotate in the other direction til it pins itself on the other side. The initial write(0) doesn’t seem to make it do anything either. I tried changing the pulse max and min, and it made the servo respond differently to the input values, but not in a position-control kind of way as far as I could tell…wtf
So I’d love to get this (servo with position control) working. In fact I can’t really get to work on the more mechanical assignment 6 til I get this, so anyone if you have any input here please comment!
My code right now looks like this. I omitted the unnecessaries (there’s other things universally, in setup, and in loop).
#include <Servo.h>
int ServoPin = 9; // servo control pin (output)
Servo Ultraman; // set servo
int angle = 96; // servo angle
void setup() {
Ultraman.attach(ServoPin);
Ultraman.setMaximumPulse(2400); // 2400: change if necessary
Ultraman.setMinimumPulse(544); // 544: change if necessary
Ultraman.write(0);
delay(1000);
Ultraman.write(angle);
}