add targetPosition, targetValue, kp & kd to pybullet_setJointMotorControl
This commit is contained in:
@@ -294,27 +294,29 @@ pybullet_resetSimulation(PyObject* self, PyObject* args)
|
|||||||
|
|
||||||
static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
//todo(erwincoumans): set max forces, kp, kd
|
//TODO(matkelcey): should this just be three methods?
|
||||||
|
|
||||||
int size;
|
int size;
|
||||||
int bodyIndex, jointIndex, controlMode;
|
int bodyIndex, jointIndex, controlMode;
|
||||||
double targetValue=0;
|
double targetValue=0;
|
||||||
|
double targetPosition=0;
|
||||||
|
double targetVelocity=0;
|
||||||
double maxForce=100000;
|
double maxForce=100000;
|
||||||
double gains=0.1;
|
double kp=0.1;
|
||||||
|
double kd=0.1;
|
||||||
int valid = 0;
|
int valid = 0;
|
||||||
|
|
||||||
|
|
||||||
if (0==sm)
|
if (0==sm)
|
||||||
{
|
{
|
||||||
PyErr_SetString(SpamError, "Not connected to physics server.");
|
PyErr_SetString(SpamError, "Not connected to physics server.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size= PySequence_Size(args);
|
size= PySequence_Size(args);
|
||||||
|
|
||||||
if (size==4)
|
if (size==4)
|
||||||
{
|
{
|
||||||
|
// for CONTROL_MODE_VELOCITY targetValue -> velocity
|
||||||
|
// for CONTROL_MODE_TORQUE targetValue -> force torque
|
||||||
if (!PyArg_ParseTuple(args, "iiid", &bodyIndex, &jointIndex, &controlMode, &targetValue))
|
if (!PyArg_ParseTuple(args, "iiid", &bodyIndex, &jointIndex, &controlMode, &targetValue))
|
||||||
{
|
{
|
||||||
PyErr_SetString(SpamError, "Error parsing arguments");
|
PyErr_SetString(SpamError, "Error parsing arguments");
|
||||||
@@ -324,7 +326,8 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
|||||||
}
|
}
|
||||||
if (size==5)
|
if (size==5)
|
||||||
{
|
{
|
||||||
|
// for CONTROL_MODE_VELOCITY targetValue -> velocity
|
||||||
|
// for CONTROL_MODE_TORQUE targetValue -> force torque
|
||||||
if (!PyArg_ParseTuple(args, "iiidd", &bodyIndex, &jointIndex, &controlMode, &targetValue, &maxForce))
|
if (!PyArg_ParseTuple(args, "iiidd", &bodyIndex, &jointIndex, &controlMode, &targetValue, &maxForce))
|
||||||
{
|
{
|
||||||
PyErr_SetString(SpamError, "Error parsing arguments");
|
PyErr_SetString(SpamError, "Error parsing arguments");
|
||||||
@@ -332,20 +335,31 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
|||||||
}
|
}
|
||||||
valid = 1;
|
valid = 1;
|
||||||
}
|
}
|
||||||
if (size==6)
|
if (size==8)
|
||||||
{
|
{
|
||||||
|
// only applicable for CONTROL_MODE_POSITION_VELOCITY_PD.
|
||||||
if (!PyArg_ParseTuple(args, "iiiddd", &bodyIndex, &jointIndex, &controlMode, &targetValue, &maxForce, &gains))
|
if (!PyArg_ParseTuple(args, "iiiddddd", &bodyIndex, &jointIndex, &controlMode, &targetPosition, &targetVelocity, &maxForce, &kp, &kd))
|
||||||
{
|
{
|
||||||
PyErr_SetString(SpamError, "Error parsing arguments");
|
PyErr_SetString(SpamError, "Error parsing arguments");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
valid = 1;
|
valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (size==8 && controlMode!=CONTROL_MODE_POSITION_VELOCITY_PD)
|
||||||
|
{
|
||||||
|
PyErr_SetString(SpamError, "8 argument call only applicable for control mode CONTROL_MODE_POSITION_VELOCITY_PD");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (controlMode==CONTROL_MODE_POSITION_VELOCITY_PD && size!=8)
|
||||||
|
{
|
||||||
|
PyErr_SetString(SpamError, "For CONTROL_MODE_POSITION_VELOCITY_PD please call with explicit targetPosition & targetVelocity");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
|
|
||||||
int numJoints;
|
int numJoints;
|
||||||
b3SharedMemoryCommandHandle commandHandle;
|
b3SharedMemoryCommandHandle commandHandle;
|
||||||
b3SharedMemoryStatusHandle statusHandle;
|
b3SharedMemoryStatusHandle statusHandle;
|
||||||
@@ -357,7 +371,7 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
|||||||
PyErr_SetString(SpamError, "Joint index out-of-range.");
|
PyErr_SetString(SpamError, "Joint index out-of-range.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((controlMode != CONTROL_MODE_VELOCITY) &&
|
if ((controlMode != CONTROL_MODE_VELOCITY) &&
|
||||||
(controlMode != CONTROL_MODE_TORQUE) &&
|
(controlMode != CONTROL_MODE_TORQUE) &&
|
||||||
(controlMode != CONTROL_MODE_POSITION_VELOCITY_PD))
|
(controlMode != CONTROL_MODE_POSITION_VELOCITY_PD))
|
||||||
@@ -365,19 +379,18 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
|||||||
PyErr_SetString(SpamError, "Illegral control mode.");
|
PyErr_SetString(SpamError, "Illegral control mode.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
commandHandle = b3JointControlCommandInit2(sm, bodyIndex,controlMode);
|
commandHandle = b3JointControlCommandInit2(sm, bodyIndex,controlMode);
|
||||||
|
|
||||||
b3GetJointInfo(sm, bodyIndex, jointIndex, &info);
|
b3GetJointInfo(sm, bodyIndex, jointIndex, &info);
|
||||||
|
|
||||||
switch (controlMode)
|
switch (controlMode)
|
||||||
{
|
{
|
||||||
case CONTROL_MODE_VELOCITY:
|
case CONTROL_MODE_VELOCITY:
|
||||||
{
|
{
|
||||||
double kd = gains;
|
|
||||||
b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetValue);
|
b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetValue);
|
||||||
b3JointControlSetKd(commandHandle,info.m_uIndex,kd);
|
b3JointControlSetKd(commandHandle, info.m_uIndex, kd);
|
||||||
b3JointControlSetMaximumForce(commandHandle,info.m_uIndex,maxForce);
|
b3JointControlSetMaximumForce(commandHandle, info.m_uIndex, maxForce);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,31 +399,30 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args)
|
|||||||
b3JointControlSetDesiredForceTorque(commandHandle, info.m_uIndex, targetValue);
|
b3JointControlSetDesiredForceTorque(commandHandle, info.m_uIndex, targetValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case CONTROL_MODE_POSITION_VELOCITY_PD:
|
case CONTROL_MODE_POSITION_VELOCITY_PD:
|
||||||
{
|
{
|
||||||
double kp = gains;
|
b3JointControlSetDesiredPosition(commandHandle, info.m_qIndex, targetPosition);
|
||||||
b3JointControlSetDesiredPosition( commandHandle, info.m_qIndex, targetValue);
|
b3JointControlSetKp(commandHandle, info.m_uIndex, kp);
|
||||||
b3JointControlSetKp(commandHandle,info.m_uIndex,kp);
|
b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetVelocity);
|
||||||
b3JointControlSetMaximumForce(commandHandle,info.m_uIndex,maxForce);
|
b3JointControlSetKd(commandHandle, info.m_uIndex, kd);
|
||||||
|
b3JointControlSetMaximumForce(commandHandle, info.m_uIndex, maxForce);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
PyErr_SetString(SpamError, "error in setJointControl.");
|
PyErr_SetString(SpamError, "Invalid number of args passed to setJointControl.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pybullet_setRealTimeSimulation(PyObject* self, PyObject* args)
|
pybullet_setRealTimeSimulation(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user