This problem was solved, see my posts dated:
« Reply #10 on: March 07, 2014, 06:12:04 pm »
« Reply #12 on: March 08, 2014, 05:59:06 am »
I'v got a problem with a sketch controlling a self-made cable to trigger a Canon point and shoot camera, a standard servo for tilting the camera and 1 continuous rotation servo (bought, not modified) used for panning the camera. Purpose of this construction is taking pictures hanging on a kite line (it is a so called KAP-rig, Kite Arial Photography). The whole is powered by two 18650 batteries (2 x 3,7 V), the servo's are powered by the Arduino, but they will never move at the same time.
The problem is that the standard servo moves erratically once in a while. At that point it moves up and down in a random way, sometimes it picks up the right direction at the next tiltstep, sometimes it wont recover at all. Things I tried to diagnose and or solve this problem includes:
- Testing the servo with A servo tester (no problem).
- Swapping the servo with another identical servo. The first servo behaved normally in another KAP rig making the same tilting and panning movements (not controlled by Arduino).
- Replacing the Boarduino (thought that the inaccuracy of the resonator could be the problem) with a Arduino Nano clone.
- Moving the trigger cable from D10 to D4.
- Replace servo,write(degrees) by servo.writeMicroseconds(uS)
- I even tried the SoftwareServo library.
Changing hardware (replacing Arduino, changing port, replacing servo) at first solved the problem, but after some time the problem re occured.
I've done tests at home with the above equipment for runs of 1 hour or more, without a problem. But when the problem occurs I'm not able to solve it. Yesterday evening I tested the equipment for 1,5 hour without a hitch, but today when I tried the KAP-rig outside the problem was back again. Bummer!
The following is a short description of my sketch:
The standard servo tilts the camera in a few steps from straight ahead to facing down (0-90 degrees), after every tilt step a pulss is given to the camera to trigger a shot. After reaching 90 degrees, the continuous rotation servo turns about 45 degrees and the tilt servo moves to the straight ahead position.
I hope somebody has any idea.
Erik
The code, in case someone is interested:
I hope
// Auto KAP
// Erik Verberne
#include <Servo.h>
int USBCHDKpin = 4;
int PanServopin=11;
int TiltServopin=12;
int LEDpin=13;
int DelayAfterPhoto = 8000;
Servo TiltServo, PanServo;
int Tiltpos = 0; // variable to store the servo position
int TiltDelay = 1000; // Time for camera to stabalize after Tilt
int TiltForwards = 0; // Straight ahead
int TiltDownwards = 90; // Facing down
int TiltForwards_ms = 950; // Pulse to instruct tilt servo to face straight ahead
int TiltDownwards_ms = 1830; // Pulse to instruct tilt servo to face down
int Tiltsteps = 3; // # steps to face down, after facing forwards
int Tiltstepsize = (TiltDownwards-TiltForwards)/Tiltsteps; // stepsize in degrees
int PanDelay = 1000;
int Panmove = 110; // Pulse to instruct PanServo to turn Clockwise
int Panstop = 95; // Pulse to instruct PanServo to stop turning
int Pan360 = 2400; // Duration at speed: Panmove for PanServo to make 1 rotation
int Pansteps = 8; // 3 steps in 1 rotation
int Pandegree = Pan360/360; // Duration at speed: Panmove for Panservo to turn 1 degree
int Panturn = 360/Pansteps; // # degrees for 1 step
void setup()
{
TiltServo.attach(TiltServopin, TiltForwards_ms, TiltDownwards_ms);
PanServo.attach(PanServopin);
pinMode(USBCHDKpin, OUTPUT);
pinMode(LEDpin, OUTPUT);
Serial.begin(9600);
digitalWrite(USBCHDKpin, LOW);
digitalWrite(LEDpin, LOW);
}
void Tilt(int Tiltpos)
{
if (Tiltpos+Tiltstepsize>TiltDownwards)
{
Tiltpos=TiltDownwards;
}
TiltServo.write(Tiltpos);
Serial.print("Tilt to ");
Serial.print(Tiltpos);
Serial.print(" wait a moment, ");
delay(TiltDelay);
}
void Pan(int Panstop)
{
Serial.print("Pan");
Serial.println(Panturn);
PanServo.write(Panmove);
delay(Panturn*Pandegree);
PanServo.write(Panstop);
/*delay(PanDelay);*/
}
void loop()
{
int servoms=0;
Serial.println("KAP start");
for (Tiltpos=TiltForwards; Tiltpos<= TiltDownwards;Tiltpos=Tiltpos + Tiltstepsize)
{
Tilt(Tiltpos);
f_shoot();
}
Pan(Panstop);
f_shoot(); /*first Pan, then take another picture facing down*/
}
void f_shoot()
{
Serial.println(" & then shoot");
pulse(1);
delay(DelayAfterPhoto);
}
void pulse(int number)
{
for (int counter=1;counter<= number;counter++)
{
digitalWrite(LEDpin, HIGH);
digitalWrite(USBCHDKpin, HIGH);
delay(110); /* pulse length, at least 100ms*/
digitalWrite(USBCHDKpin, LOW);
delay(60); /* gap between pulses, at least 50ms, but less than 500ms*/
digitalWrite(LEDpin, LOW);
}
delay(510); /* gap between pulse trains at least 500ms)*/
}


