mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpimath] Replace Pose2/3d.exp(Twist2/3d) with Pose2/3d.plus(Twist2/3d.exp()) (#8188)
This better matches math notation.
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "edu_wpi_first_math_jni_Pose3dJNI.h"
|
||||
#include "frc/geometry/Pose3d.h"
|
||||
|
||||
using namespace wpi::java;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_math_jni_Pose3dJNI
|
||||
* Method: exp
|
||||
* Signature: (DDDDDDDDDDDDD)[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL
|
||||
Java_edu_wpi_first_math_jni_Pose3dJNI_exp
|
||||
(JNIEnv* env, jclass, jdouble poseX, jdouble poseY, jdouble poseZ,
|
||||
jdouble poseQw, jdouble poseQx, jdouble poseQy, jdouble poseQz,
|
||||
jdouble twistDx, jdouble twistDy, jdouble twistDz, jdouble twistRx,
|
||||
jdouble twistRy, jdouble twistRz)
|
||||
{
|
||||
frc::Pose3d pose{
|
||||
units::meter_t{poseX}, units::meter_t{poseY}, units::meter_t{poseZ},
|
||||
frc::Rotation3d{frc::Quaternion{poseQw, poseQx, poseQy, poseQz}}};
|
||||
frc::Twist3d twist{units::meter_t{twistDx}, units::meter_t{twistDy},
|
||||
units::meter_t{twistDz}, units::radian_t{twistRx},
|
||||
units::radian_t{twistRy}, units::radian_t{twistRz}};
|
||||
|
||||
frc::Pose3d result = pose.Exp(twist);
|
||||
|
||||
const auto& resultQuaternion = result.Rotation().GetQuaternion();
|
||||
return MakeJDoubleArray(
|
||||
env, {{result.X().value(), result.Y().value(), result.Z().value(),
|
||||
resultQuaternion.W(), resultQuaternion.X(), resultQuaternion.Y(),
|
||||
resultQuaternion.Z()}});
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_math_jni_Pose3dJNI
|
||||
* Method: log
|
||||
* Signature: (DDDDDDDDDDDDDD)[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL
|
||||
Java_edu_wpi_first_math_jni_Pose3dJNI_log
|
||||
(JNIEnv* env, jclass, jdouble startX, jdouble startY, jdouble startZ,
|
||||
jdouble startQw, jdouble startQx, jdouble startQy, jdouble startQz,
|
||||
jdouble endX, jdouble endY, jdouble endZ, jdouble endQw, jdouble endQx,
|
||||
jdouble endQy, jdouble endQz)
|
||||
{
|
||||
frc::Pose3d startPose{
|
||||
units::meter_t{startX}, units::meter_t{startY}, units::meter_t{startZ},
|
||||
frc::Rotation3d{frc::Quaternion{startQw, startQx, startQy, startQz}}};
|
||||
frc::Pose3d endPose{
|
||||
units::meter_t{endX}, units::meter_t{endY}, units::meter_t{endZ},
|
||||
frc::Rotation3d{frc::Quaternion{endQw, endQx, endQy, endQz}}};
|
||||
|
||||
frc::Twist3d result = startPose.Log(endPose);
|
||||
|
||||
return MakeJDoubleArray(
|
||||
env, {{result.dx.value(), result.dy.value(), result.dz.value(),
|
||||
result.rx.value(), result.ry.value(), result.rz.value()}});
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
42
wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp
Normal file
42
wpimath/src/main/native/cpp/jni/Transform3dJNI.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "edu_wpi_first_math_jni_Transform3dJNI.h"
|
||||
#include "frc/geometry/Quaternion.h"
|
||||
#include "frc/geometry/Rotation3d.h"
|
||||
#include "frc/geometry/Transform3d.h"
|
||||
#include "frc/geometry/Twist3d.h"
|
||||
#include "units/angle.h"
|
||||
#include "units/length.h"
|
||||
|
||||
using namespace wpi::java;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_math_jni_Transform3dJNI
|
||||
* Method: log
|
||||
* Signature: (DDDDDDD)[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL
|
||||
Java_edu_wpi_first_math_jni_Transform3dJNI_log
|
||||
(JNIEnv* env, jclass, jdouble relX, jdouble relY, jdouble relZ, jdouble relQw,
|
||||
jdouble relQx, jdouble relQy, jdouble relQz)
|
||||
{
|
||||
frc::Transform3d transform3d{
|
||||
units::meter_t{relX}, units::meter_t{relY}, units::meter_t{relZ},
|
||||
frc::Rotation3d{frc::Quaternion{relQw, relQx, relQy, relQz}}};
|
||||
|
||||
frc::Twist3d result = transform3d.Log();
|
||||
|
||||
return MakeJDoubleArray(
|
||||
env, {{result.dx.value(), result.dy.value(), result.dz.value(),
|
||||
result.rx.value(), result.ry.value(), result.rz.value()}});
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
42
wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp
Normal file
42
wpimath/src/main/native/cpp/jni/Twist3dJNI.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <wpi/jni_util.h>
|
||||
|
||||
#include "edu_wpi_first_math_jni_Twist3dJNI.h"
|
||||
#include "frc/geometry/Transform3d.h"
|
||||
#include "frc/geometry/Twist3d.h"
|
||||
#include "units/angle.h"
|
||||
#include "units/length.h"
|
||||
|
||||
using namespace wpi::java;
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_math_jni_Twist3dJNI
|
||||
* Method: exp
|
||||
* Signature: (DDDDDD)[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL
|
||||
Java_edu_wpi_first_math_jni_Twist3dJNI_exp
|
||||
(JNIEnv* env, jclass, jdouble twistDx, jdouble twistDy, jdouble twistDz,
|
||||
jdouble twistRx, jdouble twistRy, jdouble twistRz)
|
||||
{
|
||||
frc::Twist3d twist{units::meter_t{twistDx}, units::meter_t{twistDy},
|
||||
units::meter_t{twistDz}, units::radian_t{twistRx},
|
||||
units::radian_t{twistRy}, units::radian_t{twistRz}};
|
||||
|
||||
frc::Transform3d result = twist.Exp();
|
||||
|
||||
const auto& resultQuaternion = result.Rotation().GetQuaternion();
|
||||
return MakeJDoubleArray(
|
||||
env, {{result.X().value(), result.Y().value(), result.Z().value(),
|
||||
resultQuaternion.W(), resultQuaternion.X(), resultQuaternion.Y(),
|
||||
resultQuaternion.Z()}});
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user