more work on proto/pybullet.proto

This commit is contained in:
erwincoumans
2018-09-01 13:49:56 -07:00
parent 9a26d4aaaf
commit 23e84ca9b6
11 changed files with 13387 additions and 285 deletions

View File

@@ -8,6 +8,7 @@
#include <grpc++/grpc++.h>
#include <grpc/support/log.h>
#include "pybullet.grpc.pb.h"
#include "LinearMath/btMinMax.h"
using grpc::Server;
using grpc::ServerAsyncResponseWriter;
@@ -26,9 +27,9 @@ SharedMemoryCommand* convertGRPCAndSubmitCommand(PyBulletCommand& grpcCommand, S
if (grpcCommand.has_loadurdfcommand())
{
auto grpcCmd = grpcCommand.loadurdfcommand();
const ::pybullet_grpc::LoadUrdfCommand& grpcCmd = grpcCommand.loadurdfcommand();
std::string fileName = grpcCmd.urdffilename();
std::string fileName = grpcCmd.filename();
if (fileName.length())
{
cmdPtr = &cmd;
@@ -45,9 +46,9 @@ SharedMemoryCommand* convertGRPCAndSubmitCommand(PyBulletCommand& grpcCommand, S
const ::pybullet_grpc::quat4& orn = grpcCmd.initialorientation();
b3LoadUrdfCommandSetStartOrientation(commandHandle, orn.x(), orn.y(), orn.z(), orn.w());
}
if (grpcCmd.hasUseMultiBody_case()== ::pybullet_grpc::LoadUrdfCommand::HasUseMultiBodyCase::kUseMultiBody)
if (grpcCmd.hasUseMultiBody_case() == ::pybullet_grpc::LoadUrdfCommand::HasUseMultiBodyCase::kUseMultiBody)
{
b3LoadUrdfCommandSetUseMultiBody( commandHandle, grpcCmd.usemultibody());
b3LoadUrdfCommandSetUseMultiBody(commandHandle, grpcCmd.usemultibody());
}
if (grpcCmd.hasGlobalScaling_case() == ::pybullet_grpc::LoadUrdfCommand::HasGlobalScalingCase::kGlobalScaling)
{
@@ -57,14 +58,200 @@ SharedMemoryCommand* convertGRPCAndSubmitCommand(PyBulletCommand& grpcCommand, S
{
b3LoadUrdfCommandSetUseFixedBase(commandHandle, grpcCmd.usefixedbase());
}
if (grpcCmd.urdfflags())
if (grpcCmd.flags())
{
b3LoadUrdfCommandSetFlags(commandHandle, grpcCmd.urdfflags());
b3LoadUrdfCommandSetFlags(commandHandle, grpcCmd.flags());
}
}
}
if (grpcCommand.has_loadsdfcommand())
{
const ::pybullet_grpc::LoadSdfCommand& grpcCmd = grpcCommand.loadsdfcommand();
std::string fileName = grpcCmd.filename();
if (fileName.length())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
b3LoadSdfCommandInit2(commandHandle, fileName.c_str());
if (grpcCmd.hasUseMultiBody_case() == ::pybullet_grpc::LoadSdfCommand::HasUseMultiBodyCase::kUseMultiBody)
{
b3LoadSdfCommandSetUseMultiBody(commandHandle, grpcCmd.usemultibody());
}
if (grpcCmd.hasGlobalScaling_case() == ::pybullet_grpc::LoadSdfCommand::HasGlobalScalingCase::kGlobalScaling)
{
b3LoadSdfCommandSetUseGlobalScaling(commandHandle, grpcCmd.globalscaling());
}
}
}
if (grpcCommand.has_loadmjcfcommand())
{
const pybullet_grpc::LoadMjcfCommand& grpcCmd = grpcCommand.loadmjcfcommand();
std::string fileName = grpcCmd.filename();
if (fileName.length())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
b3LoadMJCFCommandInit2(commandHandle, fileName.c_str());
if (grpcCmd.flags())
{
b3LoadMJCFCommandSetFlags(commandHandle, grpcCmd.flags());
}
}
}
if (grpcCommand.has_changedynamicscommand())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
const ::pybullet_grpc::ChangeDynamicsCommand& grpcCmd = grpcCommand.changedynamicscommand();
int bodyUniqueId = grpcCmd.bodyuniqueid();
int linkIndex = grpcCmd.linkindex();
b3InitChangeDynamicsInfo2(commandHandle);
if (grpcCmd.hasMass_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasMassCase::kMass)
{
b3ChangeDynamicsInfoSetMass(commandHandle, bodyUniqueId, linkIndex, grpcCmd.mass());
}
if (grpcCmd.hasLateralFriction_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasLateralFrictionCase::kLateralFriction)
{
b3ChangeDynamicsInfoSetLateralFriction(commandHandle, bodyUniqueId, linkIndex, grpcCmd.lateralfriction());
}
if (grpcCmd.hasSpinningFriction_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasSpinningFrictionCase::kSpinningFriction)
{
b3ChangeDynamicsInfoSetSpinningFriction(commandHandle, bodyUniqueId, linkIndex, grpcCmd.spinningfriction());
}
if (grpcCmd.hasRollingFriction_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasRollingFrictionCase::kRollingFriction)
{
b3ChangeDynamicsInfoSetRollingFriction(commandHandle, bodyUniqueId, linkIndex, grpcCmd.rollingfriction());
}
if (grpcCmd.hasRestitution_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasRestitutionCase::kRestitution)
{
b3ChangeDynamicsInfoSetRestitution(commandHandle, bodyUniqueId, linkIndex, grpcCmd.restitution());
}
if (grpcCmd.haslinearDamping_case() == ::pybullet_grpc::ChangeDynamicsCommand::HaslinearDampingCase::kLinearDamping)
{
b3ChangeDynamicsInfoSetLinearDamping(commandHandle, bodyUniqueId, grpcCmd.lineardamping());
}
if (grpcCmd.hasangularDamping_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasangularDampingCase::kAngularDamping)
{
b3ChangeDynamicsInfoSetAngularDamping(commandHandle, bodyUniqueId, grpcCmd.angulardamping());
}
bool hasContactDamping = grpcCmd.hasContactDamping_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasContactDampingCase::kContactDamping;
bool hasContactStiffness = grpcCmd.hasContactStiffness_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasContactStiffnessCase::kContactStiffness;
if (hasContactDamping && hasContactStiffness)
{
b3ChangeDynamicsInfoSetContactStiffnessAndDamping(commandHandle, bodyUniqueId, linkIndex, grpcCmd.contactstiffness(), grpcCmd.contactdamping());
}
if (grpcCmd.hasLocalInertiaDiagonal_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasLocalInertiaDiagonalCase::kLocalInertiaDiagonal)
{
double localInertiaDiag[3] = { grpcCmd.localinertiadiagonal().x(), grpcCmd.localinertiadiagonal().y(), grpcCmd.localinertiadiagonal().z() };
b3ChangeDynamicsInfoSetLocalInertiaDiagonal(commandHandle, bodyUniqueId, linkIndex, localInertiaDiag);
}
if (grpcCmd.hasFrictionAnchor_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasFrictionAnchorCase::kFrictionAnchor)
{
b3ChangeDynamicsInfoSetFrictionAnchor(commandHandle, bodyUniqueId, linkIndex, grpcCmd.frictionanchor());
}
if (grpcCmd.hasccdSweptSphereRadius_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasccdSweptSphereRadiusCase::kCcdSweptSphereRadius)
{
b3ChangeDynamicsInfoSetCcdSweptSphereRadius(commandHandle, bodyUniqueId, linkIndex, grpcCmd.ccdsweptsphereradius());
}
if (grpcCmd.hasContactProcessingThreshold_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasContactProcessingThresholdCase::kContactProcessingThreshold)
{
b3ChangeDynamicsInfoSetContactProcessingThreshold(commandHandle, bodyUniqueId, linkIndex, grpcCmd.contactprocessingthreshold());
}
if (grpcCmd.hasActivationState_case() == ::pybullet_grpc::ChangeDynamicsCommand::HasActivationStateCase::kActivationState)
{
b3ChangeDynamicsInfoSetActivationState(commandHandle, bodyUniqueId, grpcCmd.activationstate());
}
}
if (grpcCommand.has_getdynamicscommand())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
const ::pybullet_grpc::GetDynamicsCommand& grpcCmd = grpcCommand.getdynamicscommand();
b3GetDynamicsInfoCommandInit2(commandHandle, grpcCmd.bodyuniqueid(), grpcCmd.linkindex());
}
if (grpcCommand.has_initposecommand())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
const ::pybullet_grpc::InitPoseCommand& grpcCmd = grpcCommand.initposecommand();
b3CreatePoseCommandInit2(commandHandle, grpcCmd.bodyuniqueid());
double initialQ[MAX_DEGREE_OF_FREEDOM] = { 0 };
double initialQdot[MAX_DEGREE_OF_FREEDOM] = { 0 };
int hasInitialQ[MAX_DEGREE_OF_FREEDOM] = { 0 };
int hasInitialQdot[MAX_DEGREE_OF_FREEDOM] = { 0 };
if (grpcCmd.initialstateq_size() == grpcCmd.hasinitialstateq_size())
{
int numInitial = btMin(grpcCmd.initialstateq_size(), MAX_DEGREE_OF_FREEDOM);
for (int i = 0; i < numInitial; i++)
{
initialQ[i] = grpcCmd.initialstateq(i);
hasInitialQ[i] = grpcCmd.hasinitialstateq(i);
}
if (numInitial)
{
b3CreatePoseCommandSetQ(commandHandle, numInitial, initialQ, hasInitialQ);
}
}
else
{
printf("Error: if (grpcCmd.initialstateq_size() != grpcCmd.hasinitialstateq_size())\n");
}
if (grpcCmd.initialstateqdot_size() == grpcCmd.hasinitialstateqdot_size())
{
int numInitial = btMin(grpcCmd.initialstateqdot_size(), MAX_DEGREE_OF_FREEDOM);
for (int i = 0; i < numInitial; i++)
{
initialQdot[i] = grpcCmd.initialstateqdot(i);
hasInitialQdot[i] = grpcCmd.hasinitialstateqdot(i);
}
if (numInitial)
{
b3CreatePoseCommandSetQdots(commandHandle, numInitial, initialQdot, hasInitialQdot);
}
}
else
{
printf("Error: (grpcCmd.initialstateqdot_size() != grpcCmd.hasinitialstateqdot_size())\n");
}
}
if (grpcCommand.has_requestactualstatecommand())
{
cmdPtr = &cmd;
b3SharedMemoryCommandHandle commandHandle = (b3SharedMemoryCommandHandle)cmdPtr;
const ::pybullet_grpc::RequestActualStateCommand& grpcCmd = grpcCommand.requestactualstatecommand();
b3RequestActualStateCommandInit2(commandHandle, grpcCmd.bodyuniqueid());
if (grpcCmd.computeforwardkinematics())
{
b3RequestActualStateCommandComputeForwardKinematics(commandHandle, grpcCmd.computeforwardkinematics());
}
if (grpcCmd.computelinkvelocities())
{
b3RequestActualStateCommandComputeLinkVelocity(commandHandle, grpcCmd.computelinkvelocities());
}
}
if (grpcCommand.has_stepsimulationcommand())
{
cmdPtr = &cmd;
@@ -87,10 +274,157 @@ bool convertStatusToGRPC(const SharedMemoryStatus& serverStatus, char* bufferSer
::pybullet_grpc::LoadUrdfStatus* stat = grpcReply.mutable_urdfstatus();
b3SharedMemoryStatusHandle statusHandle = (b3SharedMemoryStatusHandle)&serverStatus;
int objectUniqueId = b3GetStatusBodyIndex(statusHandle);
stat->set_objectuniqueid(objectUniqueId);
stat->set_bodyuniqueid(objectUniqueId);
break;
}
case CMD_SDF_LOADING_COMPLETED:
{
int bodyIndicesOut[MAX_SDF_BODIES];
::pybullet_grpc::SdfLoadedStatus* stat = grpcReply.mutable_sdfstatus();
b3SharedMemoryStatusHandle statusHandle = (b3SharedMemoryStatusHandle)&serverStatus;
int numBodies = b3GetStatusBodyIndices(statusHandle, bodyIndicesOut, MAX_SDF_BODIES);
if (numBodies > MAX_SDF_BODIES)
{
printf("SDF exceeds body capacity: %d > %d", numBodies, MAX_SDF_BODIES);
}
for (int i = 0; i < numBodies; i++)
{
stat->add_bodyuniqueids(bodyIndicesOut[i]);
}
break;
}
case CMD_MJCF_LOADING_COMPLETED:
{
int bodyIndicesOut[MAX_SDF_BODIES];
::pybullet_grpc::MjcfLoadedStatus* stat = grpcReply.mutable_mjcfstatus();
b3SharedMemoryStatusHandle statusHandle = (b3SharedMemoryStatusHandle)&serverStatus;
int numBodies = b3GetStatusBodyIndices(statusHandle, bodyIndicesOut, MAX_SDF_BODIES);
if (numBodies > MAX_SDF_BODIES)
{
printf("MJCF exceeds body capacity: %d > %d", numBodies, MAX_SDF_BODIES);
}
for (int i = 0; i < numBodies; i++)
{
stat->add_bodyuniqueids(bodyIndicesOut[i]);
}
break;
}
case CMD_GET_DYNAMICS_INFO_COMPLETED:
{
b3DynamicsInfo info;
b3SharedMemoryStatusHandle statusHandle = (b3SharedMemoryStatusHandle)&serverStatus;
if (b3GetDynamicsInfo(statusHandle, &info))
{
::pybullet_grpc::GetDynamicsStatus*stat = grpcReply.mutable_getdynamicsstatus();
stat->set_mass(info.m_mass);
stat->set_lateralfriction(info.m_lateralFrictionCoeff);
stat->set_spinningfriction(info.m_spinningFrictionCoeff);
stat->set_rollingfriction(info.m_rollingFrictionCoeff);
stat->set_restitution(info.m_restitution);
stat->set_lineardamping(info.m_linearDamping);
stat->set_angulardamping(info.m_angularDamping);
stat->set_contactstiffness(info.m_contactStiffness);
stat->set_contactdamping(info.m_contactDamping);
pybullet_grpc::vec3* localInertia = stat->mutable_localinertiadiagonal();
localInertia->set_x(info.m_localInertialDiagonal[0]);
localInertia->set_y(info.m_localInertialDiagonal[1]);
localInertia->set_z(info.m_localInertialDiagonal[2]);
break;
stat->set_frictionanchor(info.m_frictionAnchor);
stat->set_ccdsweptsphereradius(info.m_ccdSweptSphereRadius);
stat->set_contactprocessingthreshold(info.m_contactProcessingThreshold);
stat->set_activationstate(info.m_activationState);
}
break;
}
case CMD_ACTUAL_STATE_UPDATE_COMPLETED:
{
b3SharedMemoryStatusHandle statusHandle = (b3SharedMemoryStatusHandle)&serverStatus;
int bodyUniqueId;
int numLinks;
int numDegreeOfFreedomQ;
int numDegreeOfFreedomU;
const double* rootLocalInertialFramePtr=0;
const double* actualStateQptr=0;
const double* actualStateQdotPtr=0;
const double* jointReactionForcesPtr = 0;
const double* linkLocalInertialFrames = 0;
const double* jointMotorForces = 0;
const double* linkStates = 0;
const double* linkWorldVelocities = 0;
if (b3GetStatusActualState2(
statusHandle, &bodyUniqueId,&numLinks,
&numDegreeOfFreedomQ,
&numDegreeOfFreedomU,
&rootLocalInertialFramePtr,
&actualStateQptr,
&actualStateQdotPtr,
&jointReactionForcesPtr,
&linkLocalInertialFrames,
&jointMotorForces,
&linkStates,
&linkWorldVelocities))
{
::pybullet_grpc::SendActualStateStatus* stat = grpcReply.mutable_actualstatestatus();
stat->set_bodyuniqueid(bodyUniqueId);
stat->set_numlinks(numLinks);
stat->set_numdegreeoffreedomq(numDegreeOfFreedomQ);
stat->set_numdegreeoffreedomu(numDegreeOfFreedomU);
for (int i = 0; i < numDegreeOfFreedomQ; i++)
{
stat->add_actualstateq( actualStateQptr[i]);
}
for (int i = 0; i < numDegreeOfFreedomU; i++)
{
stat->add_actualstateqdot( actualStateQdotPtr[i]);
}
for (int i = 0; i < 7; i++)
{
stat->add_rootlocalinertialframe(rootLocalInertialFramePtr[i]);
}
for (int i = 0; i < numLinks * 6; i++)
{
stat->add_linklocalinertialframes( linkLocalInertialFrames[i]);
}
for (int i = 0; i < numLinks * 6; i++)
{
stat->add_jointreactionforces(jointReactionForcesPtr[i]);
}
for (int i = 0; i < numLinks; i++)
{
stat->add_jointmotorforce(jointMotorForces[i]);
}
for (int i = 0; i < numLinks * 7; i++)
{
stat->add_linkstate(linkStates[i]);
}
for (int i = 0; i < numLinks * 6; i++)
{
stat->add_linkworldvelocities(linkWorldVelocities[i]);
}
}
break;
}
case CMD_CLIENT_COMMAND_COMPLETED:
{
//no action needed?
break;
}
default:
{
printf("convertStatusToGRPC: unknown status");
}
}

View File

@@ -10,8 +10,10 @@ project ("App_PhysicsServerSharedMemoryBridgeGRPC")
if os.is("Windows") then
defines { "WIN32", "_WIN32_WINNT=0x0600" }
includedirs {"../../ThirdPartyLibs/grpc/include"}
libdirs {"../../ThirdPartyLibs/grpc/lib/win64"}
links {"grpc","grpc++","grpc++_reflection","gpr",
"libprotobuf","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
"libprotobufd","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
end
if os.is("Linux") then
defines {"_LINUX"}
@@ -28,6 +30,12 @@ project ("App_PhysicsServerSharedMemoryBridgeGRPC")
files {
"main.cpp",
"ConvertGRPCBullet.cpp",
"ConvertGRPCBullet.h",
"pybullet.grpc.pb.cpp",
"pybullet.grpc.pb.h",
"pybullet.pb.cpp",
"pybullet.pb.h",
"../PhysicsClient.cpp",
"../PhysicsClient.h",
"../PhysicsDirect.cpp",
@@ -68,8 +76,10 @@ links {
if os.is("Windows") then
defines { "WIN32", "_WIN32_WINNT=0x0600" }
includedirs {"../../ThirdPartyLibs/grpc/include"}
libdirs {"../../ThirdPartyLibs/grpc/lib/win64"}
links {"grpc","grpc++","grpc++_reflection","gpr",
"libprotobuf","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
"libprotobufd","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
end
if os.is("Linux") then
defines {"_LINUX"}
@@ -146,5 +156,11 @@ myfiles =
files {
myfiles,
"main.cpp",
"ConvertGRPCBullet.cpp",
"ConvertGRPCBullet.h",
"pybullet.grpc.pb.cpp",
"pybullet.grpc.pb.h",
"pybullet.pb.cpp",
"pybullet.pb.h",
}

View File

@@ -1,5 +1,8 @@
syntax = "proto3";
//for why oneof everywhere, see the sad decision here:
//https://github.com/protocolbuffers/protobuf/issues/1606
option java_multiple_files = true;
option java_package = "io.grpc.pybullet_grpc";
option java_outer_classname = "PyBulletProto";
@@ -40,24 +43,134 @@ message StepSimulationCommand
};
message LoadUrdfCommand {
string urdfFileName=1;
string fileName=1;
vec3 initialPosition=2;
quat4 initialOrientation=3;
//for why oneof here, see the sad decision here:
//https://github.com/protocolbuffers/protobuf/issues/1606
oneof hasUseMultiBody { int32 useMultiBody=4; }
oneof hasUseFixedBase{ bool useFixedBase=5; }
int32 urdfFlags=6;
int32 flags=6;
oneof hasGlobalScaling { double globalScaling=7;
}
};
message LoadUrdfStatus {
int32 objectUniqueId=1;
int32 bodyUniqueId=1;
}
message LoadSdfCommand {
string fileName=1;
oneof hasUseMultiBody { int32 useMultiBody=2; }
oneof hasGlobalScaling { double globalScaling=3;
}
};
message SdfLoadedStatus
{
repeated int32 bodyUniqueIds=2;
}
message LoadMjcfCommand {
string fileName=1;
int32 flags=2;
};
message MjcfLoadedStatus
{
repeated int32 bodyUniqueIds=2;
}
message ChangeDynamicsCommand
{
int32 bodyUniqueId=1;
int32 linkIndex=2;
oneof hasMass { double mass=3;}
oneof hasLateralFriction { double lateralFriction=5;}
oneof hasSpinningFriction {double spinningFriction=6;}
oneof hasRollingFriction {double rollingFriction=7;}
oneof hasRestitution { double restitution=8;}
oneof haslinearDamping { double linearDamping=9;}
oneof hasangularDamping { double angularDamping=10;}
oneof hasContactStiffness { double contactStiffness=11;}
oneof hasContactDamping { double contactDamping=12;}
oneof hasLocalInertiaDiagonal { vec3 localInertiaDiagonal=13;}
oneof hasFrictionAnchor { int32 frictionAnchor=14;}
oneof hasccdSweptSphereRadius { double ccdSweptSphereRadius=15;}
oneof hasContactProcessingThreshold { double contactProcessingThreshold=16;}
oneof hasActivationState { int32 activationState=17;}
};
message GetDynamicsCommand
{
int32 bodyUniqueId=1;
int32 linkIndex=2;
};
message GetDynamicsStatus
{
double mass=3;
double lateralFriction=5;
double spinningFriction=6;
double rollingFriction=7;
double restitution=8;
double linearDamping=9;
double angularDamping=10;
double contactStiffness=11;
double contactDamping=12;
vec3 localInertiaDiagonal=13;
int32 frictionAnchor=14;
double ccdSweptSphereRadius=15;
double contactProcessingThreshold=16;
int32 activationState=17;
};
message InitPoseCommand
{
int32 bodyUniqueId=1;
repeated int32 hasInitialStateQ=2;
repeated double initialStateQ=3;
repeated int32 hasInitialStateQdot=4;
repeated double initialStateQdot=5;
};
message RequestActualStateCommand
{
int32 bodyUniqueId=1;
bool computeForwardKinematics=2;
bool computeLinkVelocities=3;
};
message SendActualStateStatus
{
int32 bodyUniqueId=1;
int32 numLinks=2;
int32 numDegreeOfFreedomQ=3;
int32 numDegreeOfFreedomU=4;
repeated double rootLocalInertialFrame=5;
//actual state is only written by the server, read-only access by client is expected
repeated double actualStateQ=6;
repeated double actualStateQdot=7;
//measured 6DOF force/torque sensors: force[x,y,z] and torque[x,y,z]
repeated double jointReactionForces=8;
repeated double jointMotorForce=9;
repeated double linkState=10;
repeated double linkWorldVelocities=11;//linear velocity and angular velocity in world space (x/y/z each).
repeated double linkLocalInertialFrames=12;
};
// The request message containing the command
message PyBulletCommand {
@@ -67,8 +180,13 @@ message PyBulletCommand {
LoadUrdfCommand loadUrdfCommand = 3;
TerminateServerCommand terminateServerCommand=4;
StepSimulationCommand stepSimulationCommand= 5;
LoadSdfCommand loadSdfCommand=6;
LoadMjcfCommand loadMjcfCommand=7;
ChangeDynamicsCommand changeDynamicsCommand=8;
GetDynamicsCommand getDynamicsCommand=9;
InitPoseCommand initPoseCommand=10;
RequestActualStateCommand requestActualStateCommand=11;
}
}
@@ -79,6 +197,10 @@ message PyBulletStatus {
oneof status
{
LoadUrdfStatus urdfStatus = 2;
SdfLoadedStatus sdfStatus = 3;
MjcfLoadedStatus mjcfStatus = 4;
GetDynamicsStatus getDynamicsStatus = 5;
SendActualStateStatus actualStateStatus = 6;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,22 +7,58 @@ import grpc
import pybullet_pb2
import pybullet_pb2_grpc
#todo: how to add this?
MJCF_COLORS_FROM_FILE = 512
def run():
channel = grpc.insecure_channel('localhost:50051')
stub = pybullet_pb2_grpc.PyBulletAPIStub(channel)
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(loadUrdfCommand=pybullet_pb2.LoadUrdfCommand(urdfFileName="plane.urdf", initialPosition=pybullet_pb2.vec3(x=0,y=0,z=0), useMultiBody=False, useFixedBase=True, globalScaling=2, urdfFlags = 1)))
print("PyBullet client received: " , response.statusType)
print("URDF objectid =", response.urdfStatus.objectUniqueId)
print("grpc.insecure_channel")
channel = grpc.insecure_channel('localhost:50051')
print("pybullet_pb2_grpc.PyBulletAPIStub")
stub = pybullet_pb2_grpc.PyBulletAPIStub(channel)
response=0
print("submit LoadSdfCommand")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(loadSdfCommand=pybullet_pb2.LoadSdfCommand(fileName="two_cubes.sdf", useMultiBody=True, globalScaling=2)))
print("PyBullet client received: " , response)
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(stepSimulationCommand=pybullet_pb2.StepSimulationCommand()))
print("PyBullet client received: " , response.statusType)
print("submit LoadMjcfCommand")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(loadMjcfCommand=pybullet_pb2.LoadMjcfCommand(fileName="mjcf/humanoid.xml",flags=MJCF_COLORS_FROM_FILE)))
print("PyBullet client received: " , response)
print("submit LoadUrdfCommand ")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(loadUrdfCommand=pybullet_pb2.LoadUrdfCommand(fileName="door.urdf", initialPosition=pybullet_pb2.vec3(x=0,y=0,z=0), useMultiBody=True, useFixedBase=True, globalScaling=2, flags = 1)))
print("PyBullet client received: " , response)
bodyUniqueId = response.urdfStatus.bodyUniqueId
print("submit ChangeDynamicsCommand ")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(changeDynamicsCommand=pybullet_pb2.ChangeDynamicsCommand(bodyUniqueId=bodyUniqueId, linkIndex=-1, mass=10)))
print("PyBullet client received: " , response)
print("submit GetDynamicsCommand ")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(getDynamicsCommand=pybullet_pb2.GetDynamicsCommand(bodyUniqueId=bodyUniqueId, linkIndex=-1)))
print("PyBullet client received: " , response)
print("submit InitPoseCommand")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(initPoseCommand=pybullet_pb2.InitPoseCommand(bodyUniqueId=bodyUniqueId, initialStateQ=[1,2,3],hasInitialStateQ=[1,1,1])))
print("PyBullet client received: " , response)
print("submit RequestActualStateCommand")
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(requestActualStateCommand=pybullet_pb2.RequestActualStateCommand(bodyUniqueId=bodyUniqueId, computeForwardKinematics=True, computeLinkVelocities=True )))
print("PyBullet client received: " , response)
#for i in range (1000):
# print("submit StepSimulationCommand: ", i)
# response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(stepSimulationCommand=pybullet_pb2.StepSimulationCommand()))
# print("PyBullet client received: " , response.statusType)
#response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(terminateServerCommand=pybullet_pb2.TerminateServerCommand()))
#print("PyBullet client received: " , response.statusType)
#print("TerminateServerCommand")
#response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(terminateServerCommand=pybullet_pb2.TerminateServerCommand()))
#print("PyBullet client received: " , response.statusType)
if __name__ == '__main__':
run()
run()

File diff suppressed because one or more lines are too long