Discussion

Left ArrowBack to discussions page
pgb123pgb123 Posts: 12 Apprentice

Hi, I've been in IT for 30 years but very new to UR's and Robotiq, so hoping someone here can give some guidance.

A client needs to have a joystick control his UR3 and Robotiq 2 finger gripper urgently for a very high profile showcase.

This youtube video shows EXACTLY what's needed but I can't seem to get hold of the video creator.

https://youtu.be/TCSKiWe-4jo

It’s suddenly clicked for me, the guy on youtube basically said it’s simple, just connect the joystick wires to the analogue ports on the UR controller and rest is in polyscope.

Joysticks have been around for decades and are pretty simple devices from what I can see.

Now there’s only 4 analogue inputs on the UR controller, so that explains why in the video there’s no wrist movement, but I reckon the customer will accept that, so we use 3 for the Base, Arm and Elbow plus one more to open/close the gripper.

So assuming the above is true then what would the actual program in Polyscope look like?

Here’s some bad pseudo code:

 

If Analogue1 > 0 then rotate base (in proportion to signal)

If Analogue2 > 0 then rotate arm

If Analogue3 > 0 then rotate elbow

If Analogue4 > 0 then open gripper


Could someone help me a bit with the coding? 

And would there be any way to control the wrists (that would be nice but probably not absolutely needed)

My apologies as I'd posted this in the wrong forum, it's more about programming  than the gripper I think.

Open to any and all suggestions/criticisms/anything

Comments

  • Fionn_MerzFionn_Merz Posts: 6Partner, Beta Tester VIsion 1.1 Program Apprentice
    This is an interesting application, Here's how I would approach it:
    1) Realistically only 2 of the Analog Inputs are usable, as the other 2 are on the tool flange, and you probably wouldn't want to run a loom the whole way up the arm. 
    2) The joystick probably outputs a voltage that is 0 at center, and goes positive or negative as it is manipulated on an axis (I assume). You may have to wire a voltage divider so the output is  0V on one extreme of its range, and 10V at the other.
    3) One analog input will be your X, the other the Y. Further, you will need two buttons to control +Z and -Z.
    4) I would suggest that rather than mapping the joystick axes to joints, you should map them to cartesian velocities. Then you will be able to jog the arm over the whole workspace, albeit without changing the orientation.
    4) In the linked video, the arm only moves on one linear axis at a time. If you're ok with this limitation then the program is relatively straightforward. Using pose_trans() and get_actual_tcp_pose(), you can generate a new pose relative to the current tool pose. You then use a continually evaluated If...Else to jog the arm there. The If will use the state of the analogue input as its argument. By setting a low acceleration and high velocity, the arm should smoothly ramp up to speed. Use stopl() after the IF to avoid a protective stop when the joystick is released.  For the X axis this may look like:

    ## IF is continually evaluated ##

    If (analog_in0 > 5.1) :  
       pose_current = get_actual_tcp_pose()
       pose_target = pose_trans(pose_current,p[1,0,0,0,0,0])
       movel(posetarget,0.2,1)
    end

    stopl(3)

    If (analog_in0 < 4.9) :  
       pose_current = get_actual_tcp_pose()
       pose_target = pose_trans(pose_current,p[-1,0,0,0,0,0])
       movel(posetarget,0.2,1)
    end

    stopl(3)

    You'll need this code 3 more times, for each axis positive and negative, just change the comparison in the If, and the pose given as an argument to the pose_trans().
    5) If you want to combine linear movements simultaneously (a diagonal movement), you'll need to use servoj() I think. I'm not well versed in using that command so am little help, but I can say you will need to use get_inverse_kin() to go from cartesian coordinates to jointspace, which servoj() uses.
  • pgb123pgb123 Posts: 12 Apprentice
    Hi Fionn, thanks for the invaluable feedback and great suggestions!

    Re your points

    1) OK yes and I've done some reading on USB as that has just 4 wires (VCC, Ground, Data+, Data-) yet some of the joysticks have up to 16 axis and 64 buttons, somehow this is all sent down just the 2 data wires

    2) I am struggling to find anything on how this works and if a voltage divider is needed, I did find this article that goes into lots of related info re joysticks wiring http://www.slagcoin.com/joystick/pcb_wiring.html

    3) That would be OK

    4) Re the cartesian velocities, great suggestion!

    4b) Re moving one plane at a time, it's probably not ideal, but if it works then should be OK

    5) Re diagonal moves and servoj, would anyone else have any suggestions re that?

    For reference I've found this very simple arduino code (with video) on how to connect a basic joystick https://www.brainy-bits.com/arduino-joystick-tutorial/ 

    // Arduino pin numbers
    const int SW_pin = 2; // digital pin connected to switch output
    const int X_pin = 0; // analog pin connected to X output
    const int Y_pin = 1; // analog pin connected to Y output
    
    void setup() {
      pinMode(SW_pin, INPUT);
      digitalWrite(SW_pin, HIGH);
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.print("Switch:  ");
      Serial.print(digitalRead(SW_pin));
      Serial.print("\n");
      Serial.print("X-axis: ");
      Serial.print(analogRead(X_pin));
      Serial.print("\n");
      Serial.print("Y-axis: ");
      Serial.println(analogRead(Y_pin));
      Serial.print("\n\n");
      delay(500);
    }
    Tho how that translates to polyscope code is beyond me at this stage

    There's also this big library of arduino code on github that can supposedly handle loads of axis and buttons https://github.com/MHeironimus/ArduinoJoystickLibrary

    Still very open to any help/suggestions/criticisms/anything

  • Fionn_MerzFionn_Merz Posts: 6Partner, Beta Tester VIsion 1.1 Program Apprentice
    No Problem :smiley:
    To use the analog inputs, I would bypass the USB altogether. I imagine the joystick has a microcontroller of some sort which is taking the state of all the buttons and axes, and converting that into the USB protocol. If you take apart the joystick I would guess you'll find a pair of variable resistors or such, which are transducing the joystick position into voltage. Solder some connections onto these, and bypass the controller altogether. Same would apply to the buttons.
    Now, if you can somehow get the joystick to communicate with an arduino via USB, then you could have the arduino convert from USB back to analog. Then you wouldn't need to break the joystick.
  • pgb123pgb123 Posts: 12 Apprentice
    One of the gurus at UR has at last responded and apparently suggested we run up a python server on a laptop connected to the robot controller, plug the joystick into the laptop then use python code to control the robot. Given where the suggestion has come from I might try that first.

    I've used python a very little bit and keen to learn more (I'm more of a fortran and pascal type of guy :-) I discovered I have to download a library so python can see the joystick, so I'm thinking of this one as it's #2 on google https://gist.github.com/rdb/8864666 

    I've read how to setup the network from the laptop to the robot but if someone could possibly give me some python code snippets that might map the XYZ's etc from the joystick to the robot pose_trans (and other pose commands you suggested) that would be an enormous help?

    And does anyone know the command to open and close the robotiq gripper?

    Does anyone see any bit problems with this approach? (apart from needing a laptop permanently connected to the robot, which I don't mind) 

    As always, any help/suggestions/criticisms etc are very welcome

    p.s. I must add, I've read loads of the discussions on this forum and tho it seems a relatively small group, it's great to see the quality and good spirited support everyone seems to give here, I wish all forums were as good. I'll try to give back one day if I ever get my L plates off :-)

    p.p.s. If all else fails, I'll whip out my trusty soldering iron and rip open the joystick (which is a new logitech extreme pro 3D by the way)
Sign In or Register to comment.
Left ArrowBack to discussions page