Hi Community,
I am also new using arduiono and I would like to control actuators with a joystick.
I have used the code whish was used here too. I have deleted the drift part, because I thought that my problem comes from this, but it seems not. My problem is, as soon as the program is running, I can see on the seriell monitor the following information:
Start
4073954033943993923953913913913873903833893803883763863733853713833683813673783653763643733633703623393353393313403290
960
0
X: 00000 Y: 96003C0 Hat Switch: 707 Twist: 000 Slider: 000 Buttons A: 000 Buttons B: 000
016803383283363283333273303283273293243293213303193303173293153283143273143253143233143203153183163153
From my understanding x,y, Hat Switch, Twist, Slider, Buttons A, Buttons B will change their values when
I use the joystick to give input.
What I dont understand what are the long numbers, e.g. directly under start. I was trying a lot within the last month, but I haven
t found a solution.
Please, can somebody explain me the numbers?
Many thanks for your support.
-----First Page-----------
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <Servo.h>
#include "le3dp_rptparser.h"
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);
// Defines 3 Linear Actuator Pins 9, 10, 11
#define LINEARACTUATORPIN 9 // Linear Actuator Digital Pin 9
#define LINEARACTUATORPIN 10 // Linear Actuator Digital Pin 10
#define LINEARACTUATORPIN 11 // Linear Actuator Digital Pin 11
// Defines 3 Joystick Pins X, Y, T
#define JOY_PIN_X X // Joystick Analog Pin X
#define JOY_PIN_Y Y // Joystick Analog Pin Y
#define JOY_PIN_T T // Joystick Analog Pin T
#define POS_MIN 1050 //Fully retracted
#define POS_MAX 2000 //Fully extended
Servo linearActuator1; //Create servo object to control the linear actuator 1
int X; //Variables to hold the last reading from the analog pins fo the joystick. The value will be between 0 and 1023
Servo linearActuator2; //Create servo object to control the linear actuator 1
int Y; //Variables to hold the last reading from the analog pins fo the joystick. The value will be between 0 and 1023
Servo linearActuator3; //Create servo object to control the linear actuator 1
int T; //Variables to hold the last reading from the analog pins fo the joystick. The value will be between 0 and 1023
int ValueMapped1; //The youstick values will be changed (or mapped
)to new values to be set to the linear actuator 1
int ValueMapped2; //The youstick values will be changed (or mapped
)to new values to be set to the linear actuator 2
int ValueMapped3; //The youstick values will be changed (or mapped
)to new values to be set to the linear actuator 3
int LinearValue = 1500; // Current positional value being sent to the linear actuator. Start at the centered position
int speed = -1; // Alter this value to change the speed of the system. Higher values mean higer speeds
void setup()
{
linearActuator1.attach(9);
linearActuator1.attach(10);
linearActuator1.attach(11);
Serial.begin( 115200 );
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
if (!Hid.SetReportParser(0, &Joy))
ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
}
void loop()
{
Usb.Task();
// Initalize servos
linearActuator1.attach(LINEARACTUATORPIN, POS_MIN, POS_MAX); // Attaches/activates the linearactuator on Pin LINEARACTUATORPIN
linearActuator2.attach(LINEARACTUATORPIN, POS_MIN, POS_MAX); // Attaches/activates the linearactuator on Pin LINEARACTUATORPIN
linearActuator3.attach(LINEARACTUATORPIN, POS_MIN, POS_MAX); // Attaches/activates the linearactuator on Pin LINEARACTUATORPIN
// Use the write Microseconds to set the linear actuator to a dafault centered position
linearActuator1.write(LinearValue);
linearActuator2.write(LinearValue);
linearActuator3.write(LinearValue);
/**Actuator 1 Positions/
// Read the values from the joystick
int angle1 = analogRead(JOY_PIN_X);
// Only update if the joystick is outside the deadzone (i.e. moved outside the centre positon)
{
ValueMapped1 = map(angle1, 0, 1023, speed, -speed);
// Map analog value form native joystick value (0 to 1023) to incremental chage (speed to -speed).
LinearValue = LinearValue + ValueMapped1;
//Add mapped joystick value to present value
}
// Use the write Microsecond to set the servos to their new positions
linearActuator1.write(LinearValue);
Serial.print(angle1);
delay(10);
//Waits for the servo to get they're in position before continuing
/**Actuator Positions 2/
// Read the values from the joystick
int angle2 = analogRead(JOY_PIN_Y);
// Only update if the joystick is outside the deadzone (i.e. moved outside the centre positon)
{
ValueMapped2 = map(angle2, 0, 1023, speed, -speed);
// Map analog value form native joystick value (0 to 1023) to incremental chage (speed to -speed).
LinearValue = LinearValue + ValueMapped2;
//Add mapped joystick value to present value
}
// Use the write Microsecond to set the servos to their new positions
linearActuator2.write(LinearValue);
Serial.print(angle2);
delay(10);
//Waits for the servo to get they're in position before continuing
/****************************** Actuator Positions 3 *****************************/
// Read the values from the joystick
int angle3 = analogRead(JOY_PIN_T);
// Only update if the joystick is outside the deadzone (i.e. moved outside the centre positon)
{
ValueMapped3 = map(angle3, 0, 1023, speed, -speed);
// Map analog value form native joystick value (0 to 1023) to incremental chage (speed to -speed).
LinearValue = LinearValue + ValueMapped3;
//Add mapped joystick value to present value
}
// Use the write Microsecond to set the servos to their new positions
linearActuator3.write(LinearValue);
Serial.print(angle3);
delay(10);
//Waits for the servo to get they're in position before continuing
}