expose video capture as logging command in b3RobotSimulatorClientAPI (C++) and pybullet (use STATE_LOGGING_VIDEO_MP4)
This commit is contained in:
@@ -16,7 +16,7 @@ int main(int argc, char* argv[])
|
||||
//sim->connect(eCONNECT_UDP, "localhost", 1234);
|
||||
sim->configureDebugVisualizer( COV_ENABLE_GUI, 0);
|
||||
// sim->configureDebugVisualizer( COV_ENABLE_SHADOWS, 0);//COV_ENABLE_WIREFRAME
|
||||
|
||||
sim->setTimeOut(10);
|
||||
//syncBodies is only needed when connecting to an existing physics server that has already some bodies
|
||||
sim->syncBodies();
|
||||
b3Scalar fixedTimeStep = 1./240.;
|
||||
@@ -59,7 +59,9 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
#endif
|
||||
sim->setRealTimeSimulation(false);
|
||||
|
||||
int vidLogId = -1;
|
||||
int minitaurLogId = -1;
|
||||
|
||||
while (sim->canSubmitCommand())
|
||||
{
|
||||
b3KeyboardEventsData keyEvents;
|
||||
@@ -67,14 +69,48 @@ int main(int argc, char* argv[])
|
||||
if (keyEvents.m_numKeyboardEvents)
|
||||
{
|
||||
|
||||
printf("num key events = %d]\n", keyEvents.m_numKeyboardEvents);
|
||||
//printf("num key events = %d]\n", keyEvents.m_numKeyboardEvents);
|
||||
//m_keyState is a flag combination of eButtonIsDown,eButtonTriggered, eButtonReleased
|
||||
for (int i=0;i<keyEvents.m_numKeyboardEvents;i++)
|
||||
{
|
||||
printf("keyEvent[%d].m_keyCode = %d, state = %d\n", i,keyEvents.m_keyboardEvents[i].m_keyCode,keyEvents.m_keyboardEvents[i].m_keyState);
|
||||
if (keyEvents.m_keyboardEvents[i].m_keyCode=='0')
|
||||
{
|
||||
if ( keyEvents.m_keyboardEvents[i].m_keyState&eButtonTriggered)
|
||||
{
|
||||
if (vidLogId < 0)
|
||||
{
|
||||
vidLogId = sim->startStateLogging(STATE_LOGGING_VIDEO_MP4,"video.mp4");
|
||||
}
|
||||
else
|
||||
{
|
||||
sim->stopStateLogging(vidLogId);
|
||||
vidLogId=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keyEvents.m_keyboardEvents[i].m_keyCode=='m')
|
||||
{
|
||||
if ( minitaurLogId<0 && keyEvents.m_keyboardEvents[i].m_keyState&eButtonTriggered)
|
||||
{
|
||||
minitaurLogId = sim->startStateLogging(STATE_LOGGING_MINITAUR,"simlog.bin");
|
||||
}
|
||||
if (minitaurLogId>=0 && keyEvents.m_keyboardEvents[i].m_keyState&eButtonReleased)
|
||||
{
|
||||
sim->stopStateLogging(minitaurLogId);
|
||||
minitaurLogId=-1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("keyEvent[%d].m_keyCode = %d, state = %d\n", i,keyEvents.m_keyboardEvents[i].m_keyCode,keyEvents.m_keyboardEvents[i].m_keyState);
|
||||
}
|
||||
}
|
||||
sim->stepSimulation();
|
||||
static double yaw=0;
|
||||
double distance = 10.5+9 * b3Sin(yaw);
|
||||
yaw+=0.008;
|
||||
sim->resetDebugVisualizerCamera(distance,yaw,20,b3MakeVector3(0,0,0.1));
|
||||
b3Clock::usleep(1000.*1000.*fixedTimeStep);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,18 @@ bool b3RobotSimulatorClientAPI::isConnected() const
|
||||
return (m_data->m_physicsClientHandle != 0);
|
||||
}
|
||||
|
||||
void b3RobotSimulatorClientAPI::setTimeOut(double timeOutInSec)
|
||||
{
|
||||
if (!isConnected())
|
||||
{
|
||||
b3Warning("Not connected");
|
||||
return;
|
||||
}
|
||||
b3SetTimeOut(m_data->m_physicsClientHandle,timeOutInSec);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void b3RobotSimulatorClientAPI::disconnect()
|
||||
{
|
||||
if (!isConnected())
|
||||
@@ -853,3 +865,18 @@ void b3RobotSimulatorClientAPI::stopStateLogging(int stateLoggerUniqueId)
|
||||
b3StateLoggingStop(commandHandle, stateLoggerUniqueId);
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
||||
}
|
||||
|
||||
void b3RobotSimulatorClientAPI::resetDebugVisualizerCamera(double cameraDistance, double cameraPitch, double cameraYaw, const b3Vector3& targetPos)
|
||||
{
|
||||
b3SharedMemoryCommandHandle commandHandle = b3InitConfigureOpenGLVisualizer(m_data->m_physicsClientHandle);
|
||||
if (commandHandle)
|
||||
{
|
||||
if ((cameraDistance >= 0))
|
||||
{
|
||||
b3Vector3FloatData camTargetPos;
|
||||
targetPos.serializeFloat(camTargetPos);
|
||||
b3ConfigureOpenGLVisualizerSetViewMatrix(commandHandle, cameraDistance, cameraPitch, cameraYaw, camTargetPos.m_floats);
|
||||
}
|
||||
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ public:
|
||||
|
||||
bool isConnected() const;
|
||||
|
||||
void setTimeOut(double timeOutInSec);
|
||||
|
||||
void syncBodies();
|
||||
|
||||
void resetSimulation();
|
||||
@@ -181,8 +183,9 @@ public:
|
||||
bool getLinkState(int bodyUniqueId, int linkIndex, b3LinkState* linkState);
|
||||
|
||||
void configureDebugVisualizer(enum b3ConfigureDebugVisualizerEnum flag, int enable);
|
||||
void resetDebugVisualizerCamera(double cameraDistance, double cameraPitch, double cameraYaw, const b3Vector3& targetPos);
|
||||
|
||||
int startStateLogging(b3StateLoggingType loggingType, const std::string& fileName, const b3AlignedObjectArray<int>& objectUniqueIds, int maxLogDof = -1);
|
||||
int startStateLogging(b3StateLoggingType loggingType, const std::string& fileName, const b3AlignedObjectArray<int>& objectUniqueIds=b3AlignedObjectArray<int>(), int maxLogDof = -1);
|
||||
void stopStateLogging(int stateLoggerUniqueId);
|
||||
|
||||
void getVREvents(b3VREventsData* vrEventsData);
|
||||
|
||||
Reference in New Issue
Block a user