Topic: Joystick control variables
Hi Forum
new to remoteXY so hoping someone on here can offer me suggestions.
I am using remote xy with two joystick controls connected through ESP8266 to Arduino UNO using an L298d type motor shield.
I want to use the joystick controls to operate the 4 dc motors on the shield separately to control an RC model.
My problem is when i try to use the joystick x, y variables to run the different motors it seems to be engaging two motors on each joystick regardless of which access i am pushing the joystick on, so basically if i push joystick 1 forward on the y axis i want motor 1 to run forward and same if i pull it back, then motor two is controlled by x axis. I expect this is standard requirements but my issue is i push forward on y axis and both motors run, hope that explains sufficiently.
Following is the code i am using so would really appreciate it if someone on here has an idea where i am going wrong. As below i am using the AFMotor library to control the motors and i am just hard coding in speed for now to max.
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <RemoteXY.h>
#include <Servo.h>
#include <AFMotor.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
#define REMOTEXY_ACCESS_PASSWORD "12345678"
// Motor declarations
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,4,0,0,0,21,0,10,13,0,
5,32,68,31,30,30,2,26,31,5,
32,3,30,31,31,2,26,31
};
// this structure defines all the variables and events of your control interface
struct
{
// input variables
int8_t FrontBucket_x; // =-100..100 x-coordinate joystick position
int8_t FrontBucket_y; // =-100..100 y-coordinate joystick position
int8_t Drive_x; // =-100..100 x-coordinate joystick position
int8_t Drive_y; // =-100..100 y-coordinate joystick position
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
void setup()
{
RemoteXY_Init ();
//set joystick x,y variables to center initially
RemoteXY.FrontBucket_x = 0;
RemoteXY.FrontBucket_y = 0;
RemoteXY.Drive_x = 0;
RemoteXY.Drive_y = 0;
//set motors to stop state initially
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}
void loop()
{
RemoteXY_Handler ();
//Call functions in a constant loop
drive_stick();
steer_stick();
loader_stick();
bucket_stick();
}
//Method to control the drive control
void drive_stick()
{
if (RemoteXY.Drive_x > 0)
{
motor1.run(FORWARD);
motor1.setSpeed(255);
}
else if (RemoteXY.Drive_x < 0)
{
motor1.run(BACKWARD);
motor1.setSpeed(255);
}
else
{
motor1.run(RELEASE);
}
}
//Method to control the steering control
void steer_stick()
{
if (RemoteXY.Drive_y > 0)
{
motor2.run(FORWARD);
motor2.setSpeed(255);
}
else if (RemoteXY.Drive_y < 0)
{
motor2.run(BACKWARD);
motor2.setSpeed(255);
}
else
{
motor2.run(RELEASE);
}
}
//Method to control the loader arm
void loader_stick()
{
//Front Arm Control
if (RemoteXY.FrontBucket_x > 0)
{
motor3.run(FORWARD);
motor3.setSpeed(255);
}
else if (RemoteXY.FrontBucket_x < 0)
{
motor3.run(BACKWARD);
motor3.setSpeed(255);
}
else
{
motor3.run(RELEASE);
}
}
//Method to control the bucket
void bucket_stick()
{
if (RemoteXY.FrontBucket_y > 0)
{
motor4.run(FORWARD);
motor4.setSpeed(255);
}
else if (RemoteXY.FrontBucket_y < 0)
{
motor4.run(BACKWARD);
motor4.setSpeed(255);
}
else
{
motor4.run(RELEASE);
}
}