# Problem with speedJ

**URL:** https://forum.universal-robots.com/t/problem-with-speedj/25939
**Category:** URScript
**Created:** [January 4, 2023, 4:56am UTC](https://forum.universal-robots.com/t/problem-with-speedj/25939 "2023-01-04T04:56:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![anon12664399](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@anon12664399](https://forum.universal-robots.com/u/anon12664399)
#### Post date: [January 4, 2023, 4:56am UTC](https://forum.universal-robots.com/t/problem-with-speedj/25939/1 "2023-01-04T04:56:58Z")

</div>

I am using RTDE protocol for sending data to ursim

I am able to send data and it is getting reflected in URsim, but it is not moving.

I did same workflow with moveJ and it worked as expected.

Here is my script for your referal:

**Matlab:**  
function speedJV2(RTDE,jointsSpeed, acceleration, time)

% Write joints speed

fwrite(RTDE,76,‘uint16’) %Message size

fwrite(RTDE,85,‘uint8’) %RTDE package type

fwrite(RTDE,1,‘uint8’) %Recipe id

fwrite(RTDE,0,‘int32’) %speedJ 1st command mapping

fwrite(RTDE,1,‘int32’) %speedJ 2nd command mapping

fwrite(RTDE,jointsSpeed,‘double’) %Joint speed

fwrite(RTDE,acceleration,‘double’) % Acceleration

if nargin == 4

fwrite(RTDE,time,‘double’) % Time

else

fwrite(RTDE,0.002,‘double’) % Time

end

**UrScript**

# This is a demo of RTDE server script.

global jSpeed = [0,0,0,0,0,0]  
global pos = [0,0,0,0,0,0]  
global vel = 0  
global dT = 0  
global accel1 = 0  
global accel2 = 0  
def read\_command1():  
return read\_input\_integer\_register(1)  
end

def read\_command2():  
return read\_input\_integer\_register(2)  
end

thread speedThread():  
write\_output\_integer\_register(1, 0) # 0 indicates operation started  
while True:  
textmsg(“move\_thread started”)  
textmsg(get\_actual\_joint\_positions())  
speedj(jSpeed, a = accel2,t = dT) # URScript movej command  
break  
end  
enter\_critical  
write\_output\_integer\_register(1, -1) # indicates operation finished  
textmsg(“speed\_thread finished”)  
exit\_critical  
end

thread moveThread():  
write\_output\_integer\_register(1, 0) # 0 indicates operation started  
while True:  
textmsg(“move\_thread started”)  
textmsg(get\_actual\_joint\_positions())  
movej(pos, a = accel1, v = vel) # URScript movej command  
break  
end  
enter\_critical  
write\_output\_integer\_register(1, -1) # indicates operation finished  
textmsg(“move\_thread finished”)  
exit\_critical  
end

def programCommand2():  
textmsg(“program command started”)  
if ((cmd1 == 0) and (cmd2 ==1)):  
# reading joints value  
pos\_temp = [0,0,0,0,0,0]  
pos\_temp[0] = read\_input\_float\_register(0)  
pos\_temp[1] = read\_input\_float\_register(1)  
pos\_temp[2] = read\_input\_float\_register(2)  
pos\_temp[3] = read\_input\_float\_register(3)  
pos\_temp[4] = read\_input\_float\_register(4)  
pos\_temp[5] = read\_input\_float\_register(5)  
accel\_temp = read\_input\_float\_register(6) # reading acceleration value  
dT\_temp = read\_input\_float\_register(7) # reading time value  
enter\_critical  
jSpeed = pos\_temp  
dT = dT\_temp  
accel2 = accel\_temp  
exit\_critical  
textmsg(jSpeed)  
speed\_thrd = run speedThread()  
join speed\_thrd

```
end
return True

```

end

def programCommand1():  
textmsg(“program command started”)  
if ((cmd1 == 1) and (cmd2 ==0)):  
# reading joints value  
pos\_temp = [0,0,0,0,0,0]  
pos\_temp[0] = read\_input\_float\_register(0)  
pos\_temp[1] = read\_input\_float\_register(1)  
pos\_temp[2] = read\_input\_float\_register(2)  
pos\_temp[3] = read\_input\_float\_register(3)  
pos\_temp[4] = read\_input\_float\_register(4)  
pos\_temp[5] = read\_input\_float\_register(5)  
vel\_temp = read\_input\_float\_register(6) # reading acceleration value  
accel\_temp = read\_input\_float\_register(7) # reading velocity value  
enter\_critical  
pos = pos\_temp  
vel = vel\_temp  
accel1 = accel\_temp  
exit\_critical  
textmsg(pos)  
move\_thrd = run moveThread()  
join move\_thrd

```
end
return True

```

end

keep\_executing = True  
executing\_cmd1 = False  
executing\_cmd2 = False  
while keep\_executing:  
cmd1 = read\_command1()  
cmd2 = read\_command2()  
if ((cmd1 == 0) and (cmd2 ==0)):  
executing\_cmd1 = False  
executing\_cmd2 = False  
elif ((cmd1 == 1) and (cmd2 ==0)):  
if not executing\_cmd1:  
keep\_executing = programCommand1()  
end  
executing\_cmd1 = True  
elif ((cmd1 == 0) and (cmd2 ==1)):  
if not executing\_cmd2:  
keep\_executing = programCommand2()  
end  
executing\_cmd2 = True  
end  
sync()  
end
