Tuesday 8 April 2014

PKP (it's alive again)

In my last post about PK, I had completed the motor controller, but had not yet tested it, so I started off by getting out my UNO and writing some test control code for the motor controller:
I got the code all written up, and gave it a test with two multimeters hooked up to the outputs (Unfortunately this video is really dark, it looked lighter when I was taking it)
And hooked it all up and gave it a try (The motor directions are reversed in this video, I fixed that shortly after)
The code running on the UNO during all of these videos is as follows:

#define in1 3
#define pwm1 9
#define f1 5
#define b1 7
#define in2 4
#define pwm2 10
#define f2 6
#define b2 8
void setup()
{
  // Channel 1:
  pinMode(in1,INPUT);
  pinMode(pwm1,OUTPUT);
  pinMode(f1,OUTPUT);
  pinMode(b1,OUTPUT);
  // Channel 2:
  pinMode(in2,INPUT);
  pinMode(pwm2,OUTPUT);
  pinMode(f2,OUTPUT);
  pinMode(b2,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
 int p1=pulseIn(in1,HIGH);
 int p2=pulseIn(in2,HIGH);
 int p3=p1+p2-1500;
 int p4=p1-p2+1500;
 p1 = constrain(p3, 1200, 1800);
 p2 = constrain(p4, 1200, 1800);
//============= Channel 1 =============
 if(p1 > 1530)
 {
   int s1=map(p1, 1530, 1800, 255, 0);
   analogWrite(pwm1,s1);
   digitalWrite(b1,LOW);
   digitalWrite(f1,HIGH);
 }
 else if(p1 < 1470)
 {
  int s1=map(p1, 1470, 1200, 255, 0);
  analogWrite(pwm1,s1);
  digitalWrite(f1,LOW);
  digitalWrite(b1,HIGH);
 }
 else
 {
  analogWrite(pwm1,255);
  digitalWrite(b1,LOW);
  digitalWrite(f1,LOW);
 }
//============ Channel 2 ==============
 if(p2 > 1530)
 {
   int s2=map(p2, 1530, 1800, 255, 0);
   analogWrite(pwm2,s2);
   digitalWrite(b2,LOW);
   digitalWrite(f2,HIGH);
 }
 else if(p2 < 1470)
 {
  int s2=map(p2, 1470, 1200, 255, 0);
  analogWrite(pwm2,s2);
  digitalWrite(f2,LOW);
  digitalWrite(b2,HIGH);
 }
 else
 {
  analogWrite(pwm2,255);
  digitalWrite(b2,LOW);
  digitalWrite(f2,LOW);
 }
//====================================
delay(15);
}

For my actual outdoor run, in order to get some footage, I made up a quick little camera bracket for my transmitter, I call it the "forever alone camera mount"


And I also made a little mount for my action cam to mount on PK in place of the paintball gun, since I do not yet have the necessary parts to make it opperational yet.
And with all that set up and working, I went out and drove it around my driveway for a bit (woohoo, my first legitimate run :)) The first video is me filming, and the second is from PK's camera
Well, it works. After I finished driving it around, I stuck it in an outdoor shead, here are a couple op pics of the various parts, and the whole thing as it sits:
Motor controller:
 Arduino:
 The whole backside:
 And from the front,
 Top,
 And side:
Anyway, it runs, which brings a smile to my face :) Onward and upward!!

No comments:

Post a Comment