mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge pull request #471 from PhilipRosedale/master
Detect and stop moving on transmitter signal lost
This commit is contained in:
commit
4583f38352
4 changed files with 27 additions and 3 deletions
|
@ -877,6 +877,8 @@ void Application::idle() {
|
|||
_serialPort.readData(deltaTime);
|
||||
}
|
||||
|
||||
// Update transmitter
|
||||
|
||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/agents
|
||||
updateAvatar(deltaTime);
|
||||
|
||||
|
|
|
@ -278,6 +278,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
|
||||
// Add thrusts from Transmitter
|
||||
if (transmitter) {
|
||||
transmitter->checkForLostTransmitter();
|
||||
glm::vec3 rotation = transmitter->getEstimatedRotation();
|
||||
const float TRANSMITTER_MIN_RATE = 1.f;
|
||||
const float TRANSMITTER_MIN_YAW_RATE = 4.f;
|
||||
|
|
|
@ -20,11 +20,25 @@ Transmitter::Transmitter() :
|
|||
_isConnected(false),
|
||||
_lastRotationRate(0,0,0),
|
||||
_lastAcceleration(0,0,0),
|
||||
_estimatedRotation(0,0,0)
|
||||
_estimatedRotation(0,0,0),
|
||||
_lastReceivedPacket(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Transmitter::checkForLostTransmitter() {
|
||||
// If we are in motion, check for loss of transmitter packets
|
||||
if (glm::length(_estimatedRotation) > 0.f) {
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
const int TIME_TO_ASSUME_LOST_MSECS = 2000;
|
||||
int msecsSinceLast = diffclock(_lastReceivedPacket, &now);
|
||||
if (msecsSinceLast > TIME_TO_ASSUME_LOST_MSECS) {
|
||||
resetLevels();
|
||||
printLog("Transmitter signal lost.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
void Transmitter::resetLevels() {
|
||||
_lastRotationRate *= 0.f;
|
||||
_estimatedRotation *= 0.f;
|
||||
|
@ -34,6 +48,11 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
|||
const int PACKET_HEADER_SIZE = 1; // Packet's first byte is 'T'
|
||||
const int ROTATION_MARKER_SIZE = 1; // 'R' = Rotation (clockwise about x,y,z)
|
||||
const int ACCELERATION_MARKER_SIZE = 1; // 'A' = Acceleration (x,y,z)
|
||||
if (!_lastReceivedPacket) {
|
||||
_lastReceivedPacket = new timeval;
|
||||
}
|
||||
gettimeofday(_lastReceivedPacket, NULL);
|
||||
|
||||
if (numBytes == PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE
|
||||
+ sizeof(_lastRotationRate) + sizeof(_lastAcceleration)
|
||||
+ sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) {
|
||||
|
@ -69,12 +88,12 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
|||
_estimatedRotation.y *= (1.f - DECAY_RATE * DELTA_TIME);
|
||||
|
||||
if (!_isConnected) {
|
||||
printf("Transmitter V2 Connected.\n");
|
||||
printLog("Transmitter Connected.\n");
|
||||
_isConnected = true;
|
||||
_estimatedRotation *= 0.0;
|
||||
}
|
||||
} else {
|
||||
printf("Transmitter V2 packet read error, %d bytes.\n", numBytes);
|
||||
printLog("Transmitter packet read error, %d bytes.\n", numBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class Transmitter
|
|||
public:
|
||||
Transmitter();
|
||||
void render();
|
||||
void checkForLostTransmitter();
|
||||
void resetLevels();
|
||||
void renderLevels(int width, int height);
|
||||
bool isConnected() { return _isConnected; };
|
||||
|
@ -41,6 +42,7 @@ private:
|
|||
glm::vec3 _lastAcceleration;
|
||||
glm::vec3 _estimatedRotation;
|
||||
TouchState _touchState;
|
||||
timeval* _lastReceivedPacket;
|
||||
|
||||
#endif /* defined(__hifi__Transmitter__) */
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue