Program Listing for include/vehicle2/commands/PxVehicleCommandParams.h

↰ Return to documentation for include/vehicle2/commands/PxVehicleCommandParams.h

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#pragma once

#include "foundation/PxFoundation.h"
#include "vehicle2/PxVehicleLimits.h"
#include "vehicle2/PxVehicleParams.h"

#if !PX_DOXYGEN
namespace physx
{
namespace vehicle2
{
#endif



struct PxVehicleCommandValueResponseTable
{
    enum Enum
    {
        eMAX_NB_SPEED_RESPONSES = 64
    };

    PxReal commandValue;

    PxVehicleFixedSizeLookupTable<PxReal, eMAX_NB_SPEED_RESPONSES> speedResponses;
};

class PxVehicleCommandNonLinearResponseParams
{
public:

    enum Enum
    {
        eMAX_NB_COMMAND_VALUES = 8
    };

    PxVehicleCommandNonLinearResponseParams()
        : nbSpeedResponses(0),
          nbCommandValues(0)
    {
    }

    void clear()
    {
        nbCommandValues = 0;
        nbSpeedResponses = 0;
    }

    bool addResponse(const PxVehicleCommandValueResponseTable& commandValueSpeedResponses)
    {
        const PxReal commandValue = commandValueSpeedResponses.commandValue;
        const PxReal* speeds = commandValueSpeedResponses.speedResponses.xVals;
        const PxReal* responses = commandValueSpeedResponses.speedResponses.yVals;
        const PxU16 nb = PxU16(commandValueSpeedResponses.speedResponses.nbDataPairs);

        PX_CHECK_AND_RETURN_VAL(commandValue >= 0.0f && commandValue <= 1.0f, "PxVehicleCommandAndResponseTable::commandValue must be in range (0,1)", false);

        PX_CHECK_AND_RETURN_VAL(nbCommandValues < eMAX_NB_COMMAND_VALUES, "PxVehicleNonLinearCommandResponse::addResponse - exceeded maximum number of command responses", false);

        PX_CHECK_AND_RETURN_VAL(((nbSpeedResponses + nb) <= PxVehicleCommandValueResponseTable::eMAX_NB_SPEED_RESPONSES), "PxVehicleNonLinearCommandResponse::addResponse - exceeded maximum number of command responses", false);

        PX_CHECK_AND_RETURN_VAL((0 == nbCommandValues) || (commandValue > commandValues[nbCommandValues - 1]), "PxVehicleNonLinearCommandResponse::addResponse - command must be part of a a monotonically increasing series", false);

        PX_CHECK_AND_RETURN_VAL(nb > 0, "PxVehicleNonLinearCommandResponse::addResponse - each command response must have at least 1 point", false);

#if PX_CHECKED
        for (PxU32 i = 1; i < nb; i++)
        {
            PX_CHECK_AND_RETURN_VAL(speeds[i] > speeds[i - 1], "PxVehicleNonLinearCommandResponse::addResponse - speeds array must be a monotonically increasing series", false);
            PX_CHECK_AND_RETURN_VAL(responses[i] >= 0.0f && responses[i] <= 1.0f , "PxVehicleNonLinearCommandResponse::addResponse - response must be in range (0,1)", false);
        }
#endif

        commandValues[nbCommandValues] = commandValue;
        nbSpeedRenponsesPerCommandValue[nbCommandValues] = nb;
        speedResponsesPerCommandValue[nbCommandValues] = nbSpeedResponses;
        PxMemCopy(speedResponses + 2 * nbSpeedResponses, speeds, sizeof(PxReal)*nb);
        PxMemCopy(speedResponses + 2 * nbSpeedResponses + nb, responses, sizeof(PxReal)*nb);
        nbCommandValues++;
        nbSpeedResponses += nb;
        return true;
    }

public:

    PxReal speedResponses[PxVehicleCommandValueResponseTable::eMAX_NB_SPEED_RESPONSES * 2];

    PxU16 nbSpeedResponses;

    PxU16 speedResponsesPerCommandValue[eMAX_NB_COMMAND_VALUES];

    PxU16 nbSpeedRenponsesPerCommandValue[eMAX_NB_COMMAND_VALUES];

    PxReal commandValues[eMAX_NB_COMMAND_VALUES];

    PxU16 nbCommandValues;
};

struct PxVehicleCommandResponseParams
{
    PxVehicleCommandNonLinearResponseParams nonlinearResponse;

    PxReal wheelResponseMultipliers[PxVehicleLimits::eMAX_NB_WHEELS];

    PxF32 maxResponse;
};



#if !PX_DOXYGEN
} // namespace vehicle2
} // namespace physx
#endif