create premake/cmake file for Bullet/Extras/obj2sdf

add missing 1.sdf for Bullet/data/kitchens/1.sdf
add support for getting keyboard events (pybullet.getKeyboardEvents and b3RobotSimulatorClientAPI::getKeyboardEvents)
This commit is contained in:
Erwin Coumans
2017-03-02 12:33:22 -08:00
parent 255b21a776
commit 34fc2fb589
29 changed files with 7317 additions and 40 deletions

View File

@@ -58,6 +58,8 @@ public:
virtual void getCachedVREvents(struct b3VREventsData* vrEventsData) = 0;
virtual void getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData) = 0;
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits) = 0;
virtual void setTimeOut(double timeOutInSeconds) = 0;

View File

@@ -2493,6 +2493,33 @@ int b3SetVRCameraTrackingObject(b3SharedMemoryCommandHandle commandHandle, int o
return 0;
}
b3SharedMemoryCommandHandle b3RequestKeyboardEventsCommandInit(b3PhysicsClientHandle physClient)
{
PhysicsClient* cl = (PhysicsClient*)physClient;
b3Assert(cl);
b3Assert(cl->canSubmitCommand());
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
b3Assert(command);
command->m_type = CMD_REQUEST_KEYBOARD_EVENTS_DATA;
command->m_updateFlags = 0;
return (b3SharedMemoryCommandHandle)command;
}
void b3GetKeyboardEventsData(b3PhysicsClientHandle physClient, struct b3KeyboardEventsData* keyboardEventsData)
{
PhysicsClient* cl = (PhysicsClient* ) physClient;
if (cl)
{
cl->getCachedKeyboardEvents(keyboardEventsData);
}
}
b3SharedMemoryCommandHandle b3StateLoggingCommandInit(b3PhysicsClientHandle physClient)
{
PhysicsClient* cl = (PhysicsClient*)physClient;

View File

@@ -350,6 +350,9 @@ int b3SetVRCameraRootPosition(b3SharedMemoryCommandHandle commandHandle, double
int b3SetVRCameraRootOrientation(b3SharedMemoryCommandHandle commandHandle, double rootOrn[4]);
int b3SetVRCameraTrackingObject(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId);
b3SharedMemoryCommandHandle b3RequestKeyboardEventsCommandInit(b3PhysicsClientHandle physClient);
void b3GetKeyboardEventsData(b3PhysicsClientHandle physClient, struct b3KeyboardEventsData* keyboardEventsData);
b3SharedMemoryCommandHandle b3StateLoggingCommandInit(b3PhysicsClientHandle physClient);
int b3StateLoggingStart(b3SharedMemoryCommandHandle commandHandle, int loggingType, const char* fileName);
int b3StateLoggingAddLoggingObjectUniqueId(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId);

View File

@@ -44,6 +44,7 @@ struct PhysicsClientSharedMemoryInternalData {
btAlignedObjectArray<b3OverlappingObject> m_cachedOverlappingObjects;
btAlignedObjectArray<b3VisualShapeData> m_cachedVisualShapes;
btAlignedObjectArray<b3VRControllerEvent> m_cachedVREvents;
btAlignedObjectArray<b3KeyboardEvent> m_cachedKeyboardEvents;
btAlignedObjectArray<b3RayHitInfo> m_raycastHits;
btAlignedObjectArray<int> m_bodyIdsRequestInfo;
@@ -773,6 +774,20 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
break;
}
case CMD_REQUEST_KEYBOARD_EVENTS_DATA_COMPLETED:
{
if (m_data->m_verboseOutput)
{
b3Printf("Request keyboard events completed");
}
m_data->m_cachedKeyboardEvents.resize(serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents);
for (int i=0;i<serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents;i++)
{
m_data->m_cachedKeyboardEvents[i] = serverCmd.m_sendKeyboardEvents.m_keyboardEvents[i];
}
break;
}
case CMD_REQUEST_AABB_OVERLAP_COMPLETED:
{
if (m_data->m_verboseOutput)
@@ -1110,7 +1125,17 @@ const SharedMemoryStatus* PhysicsClientSharedMemory::processServerStatus() {
}
bool PhysicsClientSharedMemory::canSubmitCommand() const {
return (m_data->m_isConnected && !m_data->m_waitingForServer);
if (m_data->m_isConnected && !m_data->m_waitingForServer)
{
if (m_data->m_testBlock1->m_magicId == SHARED_MEMORY_MAGIC_NUMBER)
{
return true;
} else
{
return false;
}
}
return false;
}
struct SharedMemoryCommand* PhysicsClientSharedMemory::getAvailableSharedMemoryCommand() {
@@ -1177,6 +1202,13 @@ void PhysicsClientSharedMemory::getCachedVREvents(struct b3VREventsData* vrEvent
&m_data->m_cachedVREvents[0] : 0;
}
void PhysicsClientSharedMemory::getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData)
{
keyboardEventsData->m_numKeyboardEvents = m_data->m_cachedKeyboardEvents.size();
keyboardEventsData->m_keyboardEvents = keyboardEventsData->m_numKeyboardEvents?
&m_data->m_cachedKeyboardEvents[0] : 0;
}
void PhysicsClientSharedMemory::getCachedRaycastHits(struct b3RaycastInformation* raycastHits)
{
raycastHits->m_numRayHits = m_data->m_raycastHits.size();

View File

@@ -67,6 +67,8 @@ public:
virtual void getCachedVREvents(struct b3VREventsData* vrEventsData);
virtual void getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData);
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits);
virtual void setTimeOut(double timeOutInSeconds);

View File

@@ -175,8 +175,8 @@ struct UdpNetworkedInternalData
printf("A packet of length %lu containing '%s' was "
"received from %s on channel %u.\n",
m_event.packet->dataLength,
m_event.packet->data,
m_event.peer->data,
(char*)m_event.packet->data,
(char*)m_event.peer->data,
m_event.channelID);
}
/* Clean up the packet now that we're done using it.
@@ -186,7 +186,7 @@ struct UdpNetworkedInternalData
break;
case ENET_EVENT_TYPE_DISCONNECT:
printf("%s disconnected.\n", m_event.peer->data);
printf("%s disconnected.\n", (char*)m_event.peer->data);
break;
default:
@@ -230,8 +230,8 @@ struct UdpNetworkedInternalData
printf("A packet of length %lu containing '%s' was "
"received from %s on channel %u.\n",
m_event.packet->dataLength,
m_event.packet->data,
m_event.peer->data,
(char*)m_event.packet->data,
(char*)m_event.peer->data,
m_event.channelID);
}
@@ -271,7 +271,7 @@ struct UdpNetworkedInternalData
}
case ENET_EVENT_TYPE_DISCONNECT:
{
printf("%s disconnected.\n", m_event.peer->data);
printf("%s disconnected.\n", (char*)m_event.peer->data);
break;
}

View File

@@ -52,6 +52,8 @@ struct PhysicsDirectInternalData
btAlignedObjectArray<b3VisualShapeData> m_cachedVisualShapes;
btAlignedObjectArray<b3VRControllerEvent> m_cachedVREvents;
btAlignedObjectArray<b3KeyboardEvent> m_cachedKeyboardEvents;
btAlignedObjectArray<b3RayHitInfo> m_raycastHits;
PhysicsCommandProcessorInterface* m_commandProcessor;
@@ -667,10 +669,23 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
{
b3Printf("Request VR Events completed");
}
m_data->m_cachedVREvents.clear();
m_data->m_cachedVREvents.resize(serverCmd.m_sendVREvents.m_numVRControllerEvents);
for (int i=0;i< serverCmd.m_sendVREvents.m_numVRControllerEvents;i++)
{
m_data->m_cachedVREvents.push_back(serverCmd.m_sendVREvents.m_controllerEvents[i]);
m_data->m_cachedVREvents[i] = serverCmd.m_sendVREvents.m_controllerEvents[i];
}
break;
}
case CMD_REQUEST_KEYBOARD_EVENTS_DATA_COMPLETED:
{
if (m_data->m_verboseOutput)
{
b3Printf("Request keyboard events completed");
}
m_data->m_cachedKeyboardEvents.resize(serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents);
for (int i=0;i<serverCmd.m_sendKeyboardEvents.m_numKeyboardEvents;i++)
{
m_data->m_cachedKeyboardEvents[i] = serverCmd.m_sendKeyboardEvents.m_keyboardEvents[i];
}
break;
}
@@ -1031,6 +1046,13 @@ void PhysicsDirect::getCachedVREvents(struct b3VREventsData* vrEventsData)
&m_data->m_cachedVREvents[0] : 0;
}
void PhysicsDirect::getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData)
{
keyboardEventsData->m_numKeyboardEvents = m_data->m_cachedKeyboardEvents.size();
keyboardEventsData->m_keyboardEvents = keyboardEventsData->m_numKeyboardEvents?
&m_data->m_cachedKeyboardEvents[0] : 0;
}
void PhysicsDirect::getCachedRaycastHits(struct b3RaycastInformation* raycastHits)
{
raycastHits->m_numRayHits = m_data->m_raycastHits.size();

View File

@@ -88,6 +88,8 @@ public:
virtual void getCachedVREvents(struct b3VREventsData* vrEventsData);
virtual void getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData);
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits);
//the following APIs are for internal use for visualization:

View File

@@ -160,6 +160,11 @@ void PhysicsLoopBack::getCachedVREvents(struct b3VREventsData* vrEventsData)
return m_data->m_physicsClient->getCachedVREvents(vrEventsData);
}
void PhysicsLoopBack::getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData)
{
return m_data->m_physicsClient->getCachedKeyboardEvents(keyboardEventsData);
}
void PhysicsLoopBack::getCachedOverlappingObjects(struct b3AABBOverlapData* overlappingObjects)
{
return m_data->m_physicsClient->getCachedOverlappingObjects(overlappingObjects);

View File

@@ -72,6 +72,8 @@ public:
virtual void getCachedVREvents(struct b3VREventsData* vrEventsData);
virtual void getCachedKeyboardEvents(struct b3KeyboardEventsData* keyboardEventsData);
virtual void getCachedRaycastHits(struct b3RaycastInformation* raycastHits);
virtual void setTimeOut(double timeOutInSeconds);

View File

@@ -48,7 +48,7 @@ bool gResetSimulation = 0;
int gVRTrackingObjectUniqueId = -1;
btTransform gVRTrackingObjectTr = btTransform::getIdentity();
int gMaxNumCmdPer1ms = 100;//experiment: add some delay to avoid threads starving other threads
int gMaxNumCmdPer1ms = 10;//experiment: add some delay to avoid threads starving other threads
int gCreateObjectSimVR = -1;
int gEnableKukaControl = 0;
btVector3 gVRTeleportPos1(0,0,0);
@@ -823,6 +823,7 @@ struct PhysicsServerCommandProcessorInternalData
bool m_hasGround;
b3VRControllerEvent m_vrEvents[MAX_VR_CONTROLLERS];
btAlignedObjectArray<b3KeyboardEvent> m_keyboardEvents;
btMultiBodyFixedConstraint* m_gripperRigidbodyFixed;
btMultiBody* m_gripperMultiBody;
@@ -1932,6 +1933,42 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
hasStatus = true;
break;
};
case CMD_REQUEST_KEYBOARD_EVENTS_DATA:
{
serverStatusOut.m_sendKeyboardEvents.m_numKeyboardEvents = m_data->m_keyboardEvents.size();
if (serverStatusOut.m_sendKeyboardEvents.m_numKeyboardEvents>MAX_KEYBOARD_EVENTS)
{
serverStatusOut.m_sendKeyboardEvents.m_numKeyboardEvents = MAX_KEYBOARD_EVENTS;
}
for (int i=0;i<serverStatusOut.m_sendKeyboardEvents.m_numKeyboardEvents;i++)
{
serverStatusOut.m_sendKeyboardEvents.m_keyboardEvents[i] = m_data->m_keyboardEvents[i];
}
btAlignedObjectArray<b3KeyboardEvent> events;
//remove out-of-date events
for (int i=0;i<m_data->m_keyboardEvents.size();i++)
{
b3KeyboardEvent event = m_data->m_keyboardEvents[i];
if (event.m_keyState & eButtonIsDown)
{
event.m_keyState = eButtonIsDown;
events.push_back(event);
}
}
m_data->m_keyboardEvents.resize(events.size());
for (int i=0;i<events.size();i++)
{
m_data->m_keyboardEvents[i] = events[i];
}
serverStatusOut.m_type = CMD_REQUEST_KEYBOARD_EVENTS_DATA_COMPLETED;
hasStatus = true;
break;
};
case CMD_REQUEST_RAY_CAST_INTERSECTIONS:
{
btVector3 rayFromWorld(clientCmd.m_requestRaycastIntersections.m_rayFromPosition[0],
@@ -5050,7 +5087,7 @@ void PhysicsServerCommandProcessor::enableRealTimeSimulation(bool enableRealTime
m_data->m_allowRealTimeSimulation = enableRealTimeSim;
}
void PhysicsServerCommandProcessor::stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents)
void PhysicsServerCommandProcessor::stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents,const struct b3KeyboardEvent* keyEvents, int numKeyEvents)
{
//update m_vrEvents
for (int i=0;i<numVREvents;i++)
@@ -5090,6 +5127,31 @@ void PhysicsServerCommandProcessor::stepSimulationRealTime(double dtInSec, const
}
}
for (int i=0;i<numKeyEvents;i++)
{
const b3KeyboardEvent& event = keyEvents[i];
bool found = false;
//search a matching one first, otherwise add new event
for (int e=0;e<m_data->m_keyboardEvents.size();e++)
{
if (event.m_keyCode == m_data->m_keyboardEvents[e].m_keyCode)
{
m_data->m_keyboardEvents[e].m_keyState |= event.m_keyState;
if (event.m_keyState & eButtonIsDown)
{
m_data->m_keyboardEvents[e].m_keyState |= eButtonIsDown;
} else
{
m_data->m_keyboardEvents[e].m_keyState &= ~eButtonIsDown;
}
found=true;
}
}
if (!found)
{
m_data->m_keyboardEvents.push_back(event);
}
}
if (gResetSimulation)
{
resetSimulation();

View File

@@ -96,7 +96,7 @@ public:
//logging of object states (position etc)
void logObjectStates(btScalar timeStep);
void stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents);
void stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents, const struct b3KeyboardEvent* keyEvents, int numKeyEvents);
void enableRealTimeSimulation(bool enableRealTimeSim);
void applyJointDamping(int bodyUniqueId);

View File

@@ -255,9 +255,11 @@ struct MotionArgs
btAlignedObjectArray<MyMouseCommand> m_mouseCommands;
b3VRControllerEvent m_vrControllerEvents[MAX_VR_CONTROLLERS];
b3VRControllerEvent m_sendVrControllerEvents[MAX_VR_CONTROLLERS];
btAlignedObjectArray<b3KeyboardEvent> m_keyboardEvents;
btAlignedObjectArray<b3KeyboardEvent> m_sendKeyEvents;
PhysicsServerSharedMemory* m_physicsServerPtr;
b3AlignedObjectArray<b3Vector3> m_positions;
@@ -408,10 +410,33 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
}
}
args->m_sendKeyEvents.resize(args->m_keyboardEvents.size());
for (int i=0;i<args->m_keyboardEvents.size();i++)
{
args->m_sendKeyEvents[i] = args->m_keyboardEvents[i];
if (args->m_keyboardEvents[i].m_keyState&eButtonReleased)
{
args->m_keyboardEvents[i].m_keyState = 0;
} else
{
args->m_keyboardEvents[i].m_keyState &= ~eButtonTriggered;
}
}
//remove the 'released' events
for (int i=args->m_keyboardEvents.size()-1;i>=0;i--)
{
if (args->m_keyboardEvents[i].m_keyState==0)
{
args->m_keyboardEvents.removeAtIndex(i);
}
}
b3KeyboardEvent* keyEvents = args->m_sendKeyEvents.size()? &args->m_sendKeyEvents[0] : 0;
args->m_csGUI->unlock();
{
BT_PROFILE("stepSimulationRealTime");
args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents,numSendVrControllers);
args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents,numSendVrControllers, keyEvents, args->m_sendKeyEvents.size());
}
deltaTimeInSeconds = 0;
@@ -1086,6 +1111,59 @@ public:
return false;
}
virtual bool keyboardCallback(int key, int state){
//printf("key=%d, state=%d\n", key,state);
{
int keyIndex = -1;
//is already there?
for (int i=0;i<m_args[0].m_keyboardEvents.size();i++)
{
if (m_args[0].m_keyboardEvents[i].m_keyCode == key)
{
keyIndex = i;
break;
}
}
if (state)
{
b3KeyboardEvent ev;
ev.m_keyCode = key;
ev.m_keyState = eButtonIsDown+eButtonTriggered;
m_args[0].m_csGUI->lock();
if (keyIndex>=0)
{
if (0==(m_args[0].m_keyboardEvents[keyIndex].m_keyState & eButtonIsDown))
{
m_args[0].m_keyboardEvents[keyIndex] = ev;
}
} else
{
m_args[0].m_keyboardEvents.push_back(ev);
}
m_args[0].m_csGUI->unlock();
} else
{
m_args[0].m_csGUI->lock();
b3KeyboardEvent ev;
ev.m_keyCode = key;
ev.m_keyState = eButtonReleased;
if (keyIndex>=0)
{
m_args[0].m_keyboardEvents[keyIndex]=ev;
} else
{
m_args[0].m_keyboardEvents.push_back(ev);
}
m_args[0].m_csGUI->unlock();
}
}
/*printf("m_args[0].m_keyboardEvents.size()=%d\n", m_args[0].m_keyboardEvents.size());
for (int i=0;i<m_args[0].m_keyboardEvents.size();i++)
{
printf("key[%d]=%d state = %d\n",i,m_args[0].m_keyboardEvents[i].m_keyCode,m_args[0].m_keyboardEvents[i].m_keyState);
}
*/
if (key=='w' && state)
{
gVRTeleportPos1[0]+=0.1;

View File

@@ -225,9 +225,9 @@ void PhysicsServerSharedMemory::releaseSharedMemory()
}
void PhysicsServerSharedMemory::stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents)
void PhysicsServerSharedMemory::stepSimulationRealTime(double dtInSec, const struct b3VRControllerEvent* vrEvents, int numVREvents, const struct b3KeyboardEvent* keyEvents, int numKeyEvents)
{
m_data->m_commandProcessor->stepSimulationRealTime(dtInSec,vrEvents, numVREvents);
m_data->m_commandProcessor->stepSimulationRealTime(dtInSec,vrEvents, numVREvents, keyEvents,numKeyEvents);
}
void PhysicsServerSharedMemory::enableRealTimeSimulation(bool enableRealTimeSim)

View File

@@ -26,7 +26,7 @@ public:
virtual void processClientCommands();
virtual void stepSimulationRealTime(double dtInSec,const struct b3VRControllerEvent* vrEvents, int numVREvents);
virtual void stepSimulationRealTime(double dtInSec,const struct b3VRControllerEvent* vrEvents, int numVREvents, const struct b3KeyboardEvent* keyEvents, int numKeyEvents);
virtual void enableRealTimeSimulation(bool enableRealTimeSim);

View File

@@ -608,6 +608,12 @@ struct SendVREvents
b3VRControllerEvent m_controllerEvents[MAX_VR_CONTROLLERS];
};
struct SendKeyboardEvents
{
int m_numKeyboardEvents;
b3KeyboardEvent m_keyboardEvents[MAX_KEYBOARD_EVENTS];
};
enum eVRCameraEnums
{
VR_CAMERA_ROOT_POSITION=1,
@@ -764,6 +770,7 @@ struct SharedMemoryStatus
struct UserDebugDrawResultArgs m_userDebugDrawArgs;
struct b3UserConstraint m_userConstraintResultArgs;
struct SendVREvents m_sendVREvents;
struct SendKeyboardEvents m_sendKeyboardEvents;
struct SendRaycastHits m_raycastHits;
struct StateLoggingResultArgs m_stateLoggingResultArgs;

View File

@@ -53,6 +53,7 @@ enum EnumSharedMemoryClientCommand
CMD_SYNC_BODY_INFO,
CMD_STATE_LOGGING,
CMD_CONFIGURE_OPENGL_VISUALIZER,
CMD_REQUEST_KEYBOARD_EVENTS_DATA,
//don't go beyond this command!
CMD_MAX_CLIENT_COMMANDS,
@@ -130,7 +131,8 @@ enum EnumSharedMemoryServerStatus
CMD_STATE_LOGGING_COMPLETED,
CMD_STATE_LOGGING_START_COMPLETED,
CMD_STATE_LOGGING_FAILED,
CMD_REQUEST_KEYBOARD_EVENTS_DATA_COMPLETED,
CMD_REQUEST_KEYBOARD_EVENTS_DATA_FAILED,
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
CMD_MAX_SERVER_COMMANDS
};
@@ -251,6 +253,7 @@ enum b3VREventType
#define MAX_VR_BUTTONS 64
#define MAX_VR_CONTROLLERS 8
#define MAX_RAY_HITS 128
#define MAX_KEYBOARD_EVENTS 256
enum b3VRButtonInfo
{
@@ -280,6 +283,18 @@ struct b3VREventsData
};
struct b3KeyboardEvent
{
int m_keyCode;//ascii
int m_keyState;// see b3VRButtonInfo
};
struct b3KeyboardEventsData
{
int m_numKeyboardEvents;
struct b3KeyboardEvent* m_keyboardEvents;
};
struct b3ContactPointData
{
//todo: expose some contact flags, such as telling which fields below are valid