Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Struttering and refresh delay using python realtime control

#1
Hello,

I am trying to control a kuka using a spacemouse. I do this through roboDK and Python.
I have a link between my Python script and the kuka, I can real-time control the kuka using the Python script. But I'm experiencing weird delays and stuttering.

The stuttering:
When I run my script unconnected to the kuka, the roboDK simulation shows pretty smooth movements. But when I connect to the kuka, it moves really weirdly. It constantly pauses and accelerates. The simulation then also stutters, following the kuka accurately.

The delay:
I use a 3D spacemouse, and read the values of that mouse. When I read the values of the spacemouse without a roboDK link, it works really well. No delays between my physical movement and the program variables. But my variables fail to properly update as soon as I connect to roboDK(even without a connection to the kuka). When I'm not touching the mouse, my inputs still stay high instead of going to 0. I tried putting in pauses in case I was refreshing too fast, but it only causes weird stuttering pauses and still has a read delay.

Code:
from robodk.robolink import Robolink
from robolink import *
from robodk import *
import pyspacemouse
import time
import numpy as np


RDK = Robolink()

kuka = RDK.Item('', ITEM_TYPE_ROBOT)
frame = RDK.Item('KUKA KR 10 R1100-2 Base')
RPM = RDK.Item('RPM')

RDK.setSimulationSpeed(1)
kuka.setSpeed(speed_linear=10, speed_joints=10, accel_joints=0.5, accel_linear=0.5)

RDK.setRunMode(RUNMODE_RUN_ROBOT)


# opening the spacemouse
success = pyspacemouse.open()

speed = 5
moveXYZ = np.array([0,0,0])

def move(moveXYZ, moveR):
new_pos = transl(moveXYZ) * kuka.Pose()# * rotx(moveR)
kuka.MoveJ(new_pos, blocking=False)
#kuka.Pause(1)



if success:
while 1:
mouse = pyspacemouse.read() # update states
moveXYZ = np.array([round(mouse.y, 2), -1*round(mouse.x, 2), 0]) * speed
moveR = -1*round(mouse.yaw)/57 * speed

if(moveXYZ[0] or moveXYZ[1]) > 0.3 or (moveXYZ[0] or moveXYZ[1]) < -0.3: # or moveR > 0.3 or moveR < -0.3:
'''
framePoseAbs = kuka.Pose()
partPoseAbs = RPM.PoseAbs()
pose = framePoseAbs.inv() * partPoseAbs
'''
#print(mouse.yaw)

move(moveXYZ, moveR)


它仍然是非常基本的,我和plan to add a lot more computing in the future. I can't imagine the software not being powerful enough to calculate and update this fast, so I must be using it wrong.


The spacemouse outputs variables between -1 and 1. 0 being the passive state, it's pretty sensitive, so everything between -0.3 and 0.3 I see as an accidental movement. When I run the code, I tap the mouse and it instantly shows a correct reading. when I release the mouse, it remains at the same value for a long time, even though it should be reading 0 again.

using: kuka kr10, kr c4 controller, python 3.11, pycharm IDE, roboDK, 3D spacemouse (connexion), windows, kukaproxyvar as connection method between roboDK and kuka.
#2
Nice project!

You are stacking MoveJ commands at a high rate while the robot is moving (blocking=False).
Calling MoveJ again with the driver does not cancel the previous motion command, the robot will finish its movement.

You can retrieve the mouse position in a separate thread and store it in a queue.
If you want to exactly trace the motion that was made with the spacemouse, then empty the queue using non-blocking MoveJs (or take one and empty the queue to have the latest).

This is analog to our Game Controller. Although we are using the D-pad, and the joysticks would be closer to what you are trying to do, you might find some insights there:
https://github.com/RoboDK/Plug-In-Interf...troller.py
Please read theForum Guidelinesbefore posting!
Find useful information about RoboDK by visiting ourOnline Documentation.




Users browsing this thread:
1 Guest(s)