100 lines
4.4 KiB
C++
100 lines
4.4 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2022 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SGCoreImpl/SGJointKinematicsImpl.h"
|
|
|
|
#include "SGBuildHacks/SGInclude_Core_JointKinematics.h"
|
|
#include "SGBuildHacks/SGInclude_Core_Quat.h"
|
|
#include "SGBuildHacks/SGInclude_Core_Vect3D.h"
|
|
#include "SGCoreImpl/SGBasicHandModelImpl.h"
|
|
#include "SGCoreImpl/SGCoreEnumCast.h"
|
|
#include "SGCoreImpl/SGQuatImpl.h"
|
|
#include "SGCoreImpl/SGVect3DImpl.h"
|
|
#include "SGUtils/SGArrayUtils.h"
|
|
|
|
bool FSGJointKinematicsImpl::ForwardKinematics(const FVector& StartPosition, const FQuat& StartRotation,
|
|
const TArray<FVector>& JointLengths, const TArray<FVector>& JointAngles,
|
|
TArray<FVector>& OutNewPositions, TArray<FQuat>& OutNewRotations)
|
|
{
|
|
FSGVect3DImpl::FVect3DType StartPositionVect3D(
|
|
FSGUnits::CentimetersToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(StartPosition));
|
|
FSGQuatImpl::FQuatType StartRotationQuat(FSGQuatImpl(StartRotation).ToQuat());
|
|
|
|
std::vector<FSGVect3DImpl::FVect3DType> JointLengthsVector{
|
|
FSGArrayUtils::ToMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(JointLengths)
|
|
};
|
|
|
|
std::vector<FSGVect3DImpl::FVect3DType> JointAnglesVector{
|
|
FSGArrayUtils::ToStdVector<FVector, FSGVect3DImpl::FVect3DType, FSGVect3DImpl, &FSGVect3DImpl::ToVect3D>(
|
|
JointAngles)
|
|
};
|
|
|
|
std::vector<FSGVect3DImpl::FVect3DType> NewPositions;
|
|
std::vector<FSGQuatImpl::FQuatType> NewRotations;
|
|
|
|
const bool bResults = FSGJointKinematicsImpl::FJointKinematicsType::ForwardKinematics(
|
|
MoveTemp(StartPositionVect3D), MoveTemp(StartRotationQuat),
|
|
MoveTemp(JointLengthsVector), MoveTemp(JointAnglesVector),
|
|
NewPositions, NewRotations);
|
|
|
|
OutNewPositions = FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(NewPositions);;
|
|
OutNewRotations = FSGArrayUtils::FromStdVector<FSGQuatImpl::FQuatType, FQuat,
|
|
FSGQuatImpl, &FSGQuatImpl::ToFQuat>(NewRotations);;
|
|
|
|
return bResults;
|
|
}
|
|
|
|
bool FSGJointKinematicsImpl::ForwardKinematics(const FSGBasicHandModelImpl& Profile, const ESGFinger Finger,
|
|
const TArray<FVector>& JointAngles,
|
|
TArray<FVector>& OutNewPositions, TArray<FQuat>& OutNewRotations)
|
|
{
|
|
std::vector<FSGVect3DImpl::FVect3DType> JointAnglesVector{
|
|
FSGArrayUtils::ToStdVector<FVector, FSGVect3DImpl::FVect3DType, FSGVect3DImpl, &FSGVect3DImpl::ToVect3D>(
|
|
JointAngles)
|
|
};
|
|
|
|
std::vector<FSGVect3DImpl::FVect3DType> NewPositions;
|
|
std::vector<FSGQuatImpl::FQuatType> NewRotations;
|
|
|
|
const bool bResults = FSGJointKinematicsImpl::FJointKinematicsType::ForwardKinematics(
|
|
Profile.ToBasicHandModel(), FSGCoreEnumCast::ToEFinger(Finger), MoveTemp(JointAnglesVector),
|
|
NewPositions, NewRotations);
|
|
|
|
OutNewPositions = FSGArrayUtils::FromMillimeters<FSGVect3DImpl::FVect3DType, FSGVect3DImpl>(NewPositions);;
|
|
OutNewRotations = FSGArrayUtils::FromStdVector<FSGQuatImpl::FQuatType, FQuat,
|
|
FSGQuatImpl, &FSGQuatImpl::ToFQuat>(NewRotations);;
|
|
|
|
return bResults;
|
|
} |