Joint velocity control for Panda Robot

Typically: "How do I... ", "How can I... " questions
Post Reply
Thompson104
Posts: 1
Joined: 01 Feb 2019, 20:10

Joint velocity control for Panda Robot

Post by Thompson104 » 01 Feb 2020, 02:31

Hi all,
I'm very new to vrep so the following question may be intuitive to you.

I'm trying to simulate the performance of a Franka emika panda robot. I dragged the default panda model as my scene and I want to send(control) joint velocity with the robot. The joints are in force/torque mode, the motor enabled, and the control loop enabled. However, I'm not able to perform the simulation. The robot just runs its "default" simulation whenever I execute my code which is listed below.

I have read this post viewtopic.php?f=9&t=8247&p=31997&hilit= ... ity#p31997. However I wonder if you may provide a sample python code for me to play with? I'm not very good at programming. Really appreciate your help.


My code is attached:

Code: Select all

try:
	import sim
except:
	print ('--------------------------------------------------------------')
	print ('"sim.py" could not be imported. This means very probably that')
	print ('either "sim.py" or the remoteApi library could not be found.')
	print ('Make sure both are in the same folder as this file,')
	print ('or appropriately adjust the file "sim.py"')
	print ('--------------------------------------------------------------')
	print ('')

import time
import numpy as np
import math
print ('Program started')
sim.simxFinish(-1) # just in case, close all opened connections
clientID=sim.simxStart('127.0.0.1',19997,True,True,5000,5) # Connect to CoppeliaSim
if clientID!=-1:
	print ('Connected to remote API server')
	sim.simxSynchronous(clientID,True)
	res,objs=sim.simxGetObjects(clientID,sim.sim_handle_all,sim.simx_opmode_blocking)
	if res==sim.simx_return_ok:
		print ('Number of objects in the scene: ',len(objs))
	else:
		print ('Remote API function call returned with error code: ',res)

	num_joints = 8
	joint_names = ['Franka_joint%i' % ii for ii in range(1,num_joints)]
	print(joint_names)
	joint_handles = [sim.simxGetObjectHandle(clientID,
   					name, sim.simx_opmode_blocking)[1] for name in joint_names]


	dt = 0.015
	sim.simxSetFloatingParameter(clientID,
							sim.sim_floatparam_simulation_time_step,
							dt,
							sim.simx_opmode_oneshot)
	sim.simxStartSimulation(clientID,
			sim.simx_opmode_blocking)

	joint_target_velocities = np.zeros(len(joint_names))
	joint_target_velocities[0] = 1
	count = 0 
	track_target = []
	while count < 3:# run for 1 simulated second
		q = np.zeros(len(joint_handles))
		dq = np.zeros(len(joint_handles))

		for ii, joint_handle in enumerate(joint_handles):
			sim.simxSetJointTargetVelocity(clientID, 
						joint_handle,
						0.1,
						sim.simx_opmode_blocking)

		sim.simxSynchronousTrigger(clientID)
		count += dt
	sim.simxStopSimulation(clientID, sim.simx_opmode_blocking)
	sim.simxGetPingTime(clientID)
	sim.simxFinish(clientID)
else:
	print('failed connecting to remote API server')
print('Program ended')    	



coppelia
Site Admin
Posts: 7691
Joined: 14 Dec 2012, 00:25

Re: Joint velocity control for Panda Robot

Post by coppelia » 03 Feb 2020, 14:04

Hello,

my best guess is that you have two different controllers trying to control your robot. Try to remove the threaded child script attached to your robot base, or at least comment out that code.
Then, if you are trying to send some movement sequences to a CoppeliaSim model, have a look at the example python scripts located in programming/b0RemoteApiBindings/python/ (for examples using the B0-based remote API) or in programming/remoteApiBindings/python/python/ (for examples using the legacy remote API). Make sure you have the latest version of CoppeliaSim (V4.0.0 rev4)

Cheers

Post Reply