implement regulated j2
This commit is contained in:
@@ -41,6 +41,9 @@ public:
|
||||
void resumeMoving() noexcept;
|
||||
// Will move the motor to its current target instantly (this is jerky and may damage the hardware long-term)
|
||||
bool assumeTargetPositionImmediately() noexcept;
|
||||
bool isPositionInRange(const double pos) const noexcept { return motor.isPositionInRange(pos); };
|
||||
double getCurrentPosition() const noexcept { return motor.getCurrentPosition(); };
|
||||
double getTargetPosition() const noexcept { return motor.getTargetPosition(); };
|
||||
|
||||
void update(const double frametime);
|
||||
|
||||
|
||||
+22
-7
@@ -45,6 +45,11 @@ void MainLoop::run()
|
||||
|
||||
//YZConsolePlotter plot(-200, 200, 20, 2);
|
||||
|
||||
double j0Pos = 0;
|
||||
double j1Pos = 0;
|
||||
double j2Pos = 0;
|
||||
double j2Off = 0;
|
||||
|
||||
while (isRunning)
|
||||
{
|
||||
std::chrono::steady_clock::time_point begin =
|
||||
@@ -61,16 +66,26 @@ void MainLoop::run()
|
||||
constexpr double speed = 3000;
|
||||
VkbInputs vkbi = leftVKB.get();
|
||||
|
||||
const double moveJ0By = -vkbi.roll * speed * frametime;
|
||||
const double moveJ1By = -vkbi.pitch * speed * frametime;
|
||||
const double moveJ2By = -vkbi.yaw * speed * frametime;
|
||||
// Calculate new joint positions
|
||||
j0Pos += -vkbi.roll * speed * frametime;
|
||||
const double newJ1Pos = j1Pos + -vkbi.pitch * speed * frametime;
|
||||
const double newJ2Off = j2Off + -vkbi.yaw * speed * frametime;
|
||||
const double newJ2Pos = newJ2Off - newJ1Pos;
|
||||
|
||||
arm.getJ0().moveBy(moveJ0By, std::nullopt);
|
||||
arm.getJ1().moveBy(moveJ1By, std::nullopt);
|
||||
arm.getJ2().moveBy(moveJ2By, std::nullopt);
|
||||
arm.getJ0().moveTo(j0Pos, std::nullopt);
|
||||
// J1 and J2 are coupled. Only apply their position if they both are valid
|
||||
if (
|
||||
arm.getJ1().isPositionInRange(newJ1Pos) &&
|
||||
arm.getJ2().isPositionInRange(newJ2Pos)) {
|
||||
j1Pos = newJ1Pos;
|
||||
j2Pos = newJ2Pos;
|
||||
j2Off = newJ2Off;
|
||||
arm.getJ1().moveTo(j1Pos, std::nullopt);
|
||||
arm.getJ2().moveTo(j2Pos, std::nullopt);
|
||||
}
|
||||
|
||||
const Vector3d ef = arm.getJ2().getGlobalEndpoint();
|
||||
std::cout << ef << std::endl;
|
||||
std::cout << j2Pos << std::endl;
|
||||
//plot.draw(ef);
|
||||
|
||||
arm.update(frametime);
|
||||
|
||||
Reference in New Issue
Block a user