implement simgle joint level control for debugging
This commit is contained in:
@@ -61,6 +61,21 @@ bool Arm::assumeHomePose()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Arm::moveJ0(double theta)
|
||||||
|
{
|
||||||
|
return j0.moveTo(theta, std::nullopt);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Arm::moveJ1(double theta)
|
||||||
|
{
|
||||||
|
return j1.moveTo(theta, std::nullopt);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Arm::moveJ2(double theta)
|
||||||
|
{
|
||||||
|
return j2.moveTo(theta, std::nullopt);
|
||||||
|
}
|
||||||
|
|
||||||
Arm::~Arm()
|
Arm::~Arm()
|
||||||
{
|
{
|
||||||
oSerialBus.close();
|
oSerialBus.close();
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ public:
|
|||||||
bool assumeHomePoseImmediate();
|
bool assumeHomePoseImmediate();
|
||||||
bool assumeHomePose();
|
bool assumeHomePose();
|
||||||
|
|
||||||
|
bool moveJ0(double theta);
|
||||||
|
bool moveJ1(double theta);
|
||||||
|
bool moveJ2(double theta);
|
||||||
|
|
||||||
void update(double frametime);
|
void update(double frametime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ ArmSegment::ArmSegment(
|
|||||||
rotationAxis(rotationAxis),
|
rotationAxis(rotationAxis),
|
||||||
longitudinalAxis(longitudinalAxis),
|
longitudinalAxis(longitudinalAxis),
|
||||||
length(length),
|
length(length),
|
||||||
|
mechanicalToVirtualAngleOffset(mechanicalToVirtualAngleOffset),
|
||||||
|
homeAngle(homeAngle),
|
||||||
motor(
|
motor(
|
||||||
motorIndex,
|
motorIndex,
|
||||||
serialBus,
|
serialBus,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
void setSpeed(const double speed) noexcept { motor.setSpeed(speed); };
|
void setSpeed(const double speed) noexcept { motor.setSpeed(speed); };
|
||||||
double getMechanicalMinAngle() const { return motor.getMechanicalMinPosition(); };
|
double getMechanicalMinAngle() const { return motor.getMechanicalMinPosition(); };
|
||||||
double getMechanicalMaxAngle() const { return motor.getMechanicalMaxPosition(); };
|
double getMechanicalMaxAngle() const { return motor.getMechanicalMaxPosition(); };
|
||||||
|
double getHomeANgle() const noexcept { return homeAngle; };
|
||||||
double getSpeed() const noexcept { return motor.getSpeed(); };
|
double getSpeed() const noexcept { return motor.getSpeed(); };
|
||||||
ArmSegment* getParent() { return parent; };
|
ArmSegment* getParent() { return parent; };
|
||||||
ArmSegment const* getParent() const { return parent; };
|
ArmSegment const* getParent() const { return parent; };
|
||||||
|
|||||||
+50
-5
@@ -2,11 +2,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
MainLoop::MainLoop() noexcept:
|
MainLoop::MainLoop() noexcept:
|
||||||
arm(L"COM4")
|
arm(L"COM4")
|
||||||
{
|
{
|
||||||
arm.assumeHomePoseImmediate();
|
if (!arm.assumeHomePoseImmediate()) {
|
||||||
|
std::cerr << "Unable to move arm to home!" << std::endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainLoop& MainLoop::getInstance()
|
MainLoop& MainLoop::getInstance()
|
||||||
@@ -21,14 +25,55 @@ MainLoop::~MainLoop() noexcept
|
|||||||
|
|
||||||
void MainLoop::run()
|
void MainLoop::run()
|
||||||
{
|
{
|
||||||
static std::chrono::steady_clock::time_point lastBegin = std::chrono::high_resolution_clock::now();
|
static std::chrono::steady_clock::time_point lastBegin =
|
||||||
|
std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
while (isRunning) {
|
double j1Position = 0.0; // start at 0
|
||||||
std::chrono::steady_clock::time_point begin = std::chrono::high_resolution_clock::now();
|
const double speed = 1000.0; // units per second
|
||||||
const double frametime = (begin - lastBegin).count() * 10e-7; // in milliseconds
|
|
||||||
|
std::cout << "Main loop started\n";
|
||||||
|
std::cout << "Use UP and DOWN arrows to move J1\n";
|
||||||
|
std::cout << "Press ESC to exit\n\n";
|
||||||
|
|
||||||
|
while (isRunning)
|
||||||
|
{
|
||||||
|
std::chrono::steady_clock::time_point begin =
|
||||||
|
std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
const double frametime =
|
||||||
|
(begin - lastBegin).count() * 10e-7; // milliseconds
|
||||||
|
|
||||||
|
// -------- INPUT --------
|
||||||
|
if (GetAsyncKeyState(VK_UP) & 0x8000)
|
||||||
|
{
|
||||||
|
j1Position += speed * frametime;
|
||||||
|
arm.moveJ1(j1Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetAsyncKeyState(VK_DOWN) & 0x8000)
|
||||||
|
{
|
||||||
|
j1Position -= speed * frametime;
|
||||||
|
arm.moveJ1(j1Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
|
||||||
|
{
|
||||||
|
std::cout << "\nExit requested\n";
|
||||||
|
isRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
arm.update(frametime);
|
arm.update(frametime);
|
||||||
|
|
||||||
|
// -------- STATUS OUTPUT --------
|
||||||
|
std::cout << "\rJ1: " << std::fixed << std::setprecision(3)
|
||||||
|
<< j1Position
|
||||||
|
<< " | Frame time (ms): "
|
||||||
|
<< std::setprecision(3)
|
||||||
|
<< frametime
|
||||||
|
<< std::flush;
|
||||||
|
|
||||||
lastBegin = std::chrono::high_resolution_clock::now();
|
lastBegin = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "\nMain loop stopped\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user