Hi friends. i am trying to make a robotic arm controlled by logitech 3d extreme pro joystick. I read too much pages for months but i couldn't get far anymore and decided to want help from you.
I bought 4x sg 5010 180^servos, arduino uno, ush host shield. In usb shields library it have my joysticks' code and recognising all the axes and buttons. There is a picture of the output from serial COM. (attachment)
At first i wanted to control speed but i dont have much time for this i think. Now, i may control the position with joystick. Joystick have 3 axes and too much buttons, with these 3 axes i want to control 3 servos position. And it have 1 axis for rudder which is i will use for the claw.
Joysticks pic is
codes are 3 pages
first page
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */
#include <hid.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;
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);
Servo claw;
void setup()
{ claw.attach(3);
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();
}
2nd page
#include "le3dp_rptparser.h"
JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
joyEvents(evt)
{}
void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
bool match = true;
// Checking if there are changes in report since the method was last called
for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) {
if( buf[i] != oldPad[i] ) {
match = false;
break;
}
}
// Calling Game Pad event handler
if (!match && joyEvents) {
joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
}
}
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
Serial.print("X: ");
PrintHex<uint16_t>(evt->x, 0x80);
Serial.print(" Y: ");
PrintHex<uint16_t>(evt->y, 0x80);
Serial.print(" Hat Switch: ");
PrintHex<uint8_t>(evt->hat, 0x80);
Serial.print(" Twist: ");
PrintHex<uint8_t>(evt->twist, 0x80);
Serial.print(" Slider: ");
PrintHex<uint8_t>(evt->slider, 0x80);
Serial.print(" Buttons A: ");
PrintHex<uint8_t>(evt->buttons_a, 0x80);
Serial.print(" Buttons B: ");
PrintHex<uint8_t>(evt->buttons_b, 0x80);
Serial.println("");
}
3rd page
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__
#include <hid.h>
struct GamePadEventData
{
union { //axes and hut switch
uint32_t axes;
struct {
uint32_t x : 10;
uint32_t y : 10;
uint32_t hat : 4;
uint32_t twist : 8;
};
};
uint8_t buttons_a;
uint8_t slider;
uint8_t buttons_b;
};
class JoystickEvents
{
public:
virtual void OnGamePadChanged(const GamePadEventData *evt);
};
#define RPT_GAMEPAD_LEN sizeof(GamePadEventData)/sizeof(uint8_t)
class JoystickReportParser : public HIDReportParser
{
JoystickEvents *joyEvents;
uint8_t oldPad[RPT_GAMEPAD_LEN];
public:
JoystickReportParser(JoystickEvents *evt);
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};
#endif // __HIDJOYSTICKRPTPARSER_H__
Problem is, i couldn't control servos. I don't know how to track a way at this point. Maybe first problem is i am getting hexadecimal values for each axis. So i can't use map function like
map(angle, 0, 03ff, 0, 180)
Serial.print(<uint16_t>, HEX); instead of PrintHex<uint16_t>(evt->x, 0x80); ? It is not compiling, i couldn't understand how to do. Gentlemen, belive me, i had to finish this project in two days. I am came here with really hard days, didn't slept too many nights, studied for too many final exams, side of building a structure and learning arduino basics. Watching hours of youtube videos but couldn't finish this project. I am really ashamed for wanting help from you. It's like choosing the easy way but i had no chance any more unfortunately.
Actually my biggest problem is my teacher who responsible for my graduation project, he always said look at google and read books. I am saying this is much more for mechanical engineering student, and i wanted to learn this thing. At first i could make a robotic arm with using potentiometers and using analogRead command but i wanted to learn much more, and learnt too many things but nobody helped me for months, especially my teacher. Not a single word. Now, i will graduate in two weeks and my last subject left is this project. I wish i knew too much thigs in arduino like you but i don't. I help people in forums in our country too much and i love to. Keep that in mind. I am sorry if i spell something wrong and i don't want to be misunderstood. Now, please take my hand.
Ok. I am reading X as decimal values when i didn't write servo commands. But when i wrote
#include <hid.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);
Servo claw;
int X;
void setup()
{
claw.attach(3);
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();
int angle = map(X, 0, 1023, 0, 180);
claw.write(angle);
}
servo makes buzzing sound and serial com doesn't give anything. It stucks too.