Arudino, PS3 USB Host Shield, and Motor Shield

Hello, I’m making a PS3 arduino to control the Pan/Tilt control for Camera Jib.

Here’s what I have so far… I have the zoom in/out working fine but the problem is the motors. The Jib gives a constant power that locks the motors so they stay in place unless you move the joy stick. I don’t know how to do that with the arduino. I can move the camera left to right but with no power applied to the motors, the then free falls.

So far

trying to make:

#include <PS3USB.h>
#include <AFMotor.h>
#include <Servo.h>

USB Usb;
PS3USB PS3(&Usb);

AF_DCMotor g_motor3(3, MOTOR12_8KHZ);
AF_DCMotor g_motor4(4, MOTOR12_8KHZ);
Servo servo1;
//y = PS3.getAnalogHat(LeftHatY);
//x = PS3.getAnalogHat(LeftHatX);
void setup() {
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 USB Library Started"));
servo1.attach(9);
}

void loop() {
Usb.Task();

if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
//print X and Y values on serial monitor
Serial.print(F("\r\nLeftHatX: “));
Serial.print(PS3.getAnalogHat(LeftHatX));
Serial.print(F(”\tLeftHatY: "));
Serial.print(PS3.getAnalogHat(LeftHatY));
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
servo1.write(map(PS3.getAnalogHat(RightHatY), 0, 255, 20, 90));
}
/int direction = PS3.getAnalogHat(LeftHatY);
direction < 120 = 1;
direction > 135 = 2;
switch (direction) {
case 1:
g_motor3.run(FORWARD);
g_motor4.run(FORWARD);
break;
case 2:
g_motor3.run(BACKWARD);
g_motor4.run(BACKWARD);
break;
}
/

//set motor directions as forward for all Y < 120
if(PS3.getAnalogHat(LeftHatY) < 120) {
g_motor3.run(FORWARD);
g_motor4.run(FORWARD);
}
//set motor directions as backward for all Y > 135
if(PS3.getAnalogHat(LeftHatY) > 135) {
g_motor3.run(BACKWARD);
g_motor4.run(BACKWARD);
}
//set speeds for when the joystick is pushed directly up
if(PS3.getAnalogHat(LeftHatY) < 120 && PS3.getAnalogHat(LeftHatX) > 120 && PS3.getAnalogHat(LeftHatX) < 135) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatY)-120)*-1.66666666667);
}
//set speeds for when the joystick is pushed directly down
if(PS3.getAnalogHat(LeftHatY) > 135 && PS3.getAnalogHat(LeftHatX) > 120 && PS3.getAnalogHat(LeftHatX) < 135) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatY)-135)1.48148148148);
}
//set speeds for when joystick is pushed directly left
if(PS3.getAnalogHat(LeftHatX) < 120 && PS3.getAnalogHat(LeftHatY) > 120 && PS3.getAnalogHat(LeftHatY) < 135) {
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatX)-120)
-1.66666666667);
}
//set speeds for when joystick is pushed directly right
if(PS3.getAnalogHat(LeftHatX) > 135 && PS3.getAnalogHat(LeftHatY) > 120 && PS3.getAnalogHat(LeftHatY) < 135) {
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatX)-135)*1.48148148148);
}

//set speeds for when joystick is pushed up and right
if(PS3.getAnalogHat(LeftHatY) < 120 && PS3.getAnalogHat(LeftHatX) > 135) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatX)-255)-2.125);
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatY)-120)
-1.66666666667);
}
//set speeds for when joystick is pushed up and left
if(PS3.getAnalogHat(LeftHatY) < 120 && PS3.getAnalogHat(LeftHatX) < 120) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatY)-120)*-1.66666666667);
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatX))*2.125);
}
//set speeds for when joystick is pushed down and left
if(PS3.getAnalogHat(LeftHatY) > 135 && PS3.getAnalogHat(LeftHatX) < 120) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatY)-135)*1.48148148148);
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatX))2.125);
}
//set speeds for when joystick is pushed down and right
if(PS3.getAnalogHat(LeftHatY) > 135 && PS3.getAnalogHat(LeftHatX) > 135) {
g_motor3.setSpeed((PS3.getAnalogHat(LeftHatX)-255)
-2.125);
g_motor4.setSpeed((PS3.getAnalogHat(LeftHatY)-135)*1.48148148148);
}
//stopping
if(PS3.getAnalogHat(LeftHatY) > 120 && PS3.getAnalogHat(LeftHatY) < 135 && PS3.getAnalogHat(LeftHatX) > 120 && PS3.getAnalogHat(LeftHatX) < 135) {
g_motor3.setSpeed(0);
g_motor4.setSpeed(0);
}
}
}

PS3 Jib2 Controller.txt (3.92 KB)

Your video shows servos, but the code is for DC motors...?

Hey Mark, the servo is controlled the PS3 Right analog for zooming in/out that's working fine.

if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
servo1.write(map(PS3.getAnalogHat(RightHatY), 0, 255, 20, 90));
}

I didn't make a video yet of the motors which will be controlled by the PS3 Left analog.

nemesis27:
Hey Mark, the servo is controlled the PS3 Right analog for zooming in/out that's working fine.

if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
servo1.write(map(PS3.getAnalogHat(RightHatY), 0, 255, 20, 90));
}

I didn't make a video yet of the motors which will be controlled by the PS3 Left analog.

Have you been able to finish this code for DC motors?

I'm also trying to control a TANK-only vehicle using the left control of the PS3.

But I want to control the speed and Giro too, and for this I would need to use the MAP function ..

Did you get adjusted?