2022-12-05 12:17:23 +08:00
|
|
|
#include "control/unitreeArm.h"
|
2022-11-11 18:17:07 +08:00
|
|
|
|
2022-11-16 16:23:36 +08:00
|
|
|
using namespace UNITREE_ARM;
|
|
|
|
|
2022-11-11 18:17:07 +08:00
|
|
|
class Z1ARM : public unitreeArm{
|
|
|
|
public:
|
2022-11-15 16:05:20 +08:00
|
|
|
Z1ARM():unitreeArm(true){
|
|
|
|
runThread = new LoopFunc("Z1LowCmd", 0.002, boost::bind(&Z1ARM::run, this));
|
2022-11-11 18:17:07 +08:00
|
|
|
};
|
|
|
|
~Z1ARM(){delete runThread;};
|
|
|
|
void run();
|
|
|
|
LoopFunc *runThread;
|
|
|
|
|
|
|
|
double direction;
|
|
|
|
double velocity = 0.5;
|
2022-07-20 11:20:01 +08:00
|
|
|
};
|
|
|
|
|
2022-11-11 18:17:07 +08:00
|
|
|
void Z1ARM::run(){
|
|
|
|
tau(0) = direction*3.;// torque
|
|
|
|
q(1) += direction*_ctrlComp->dt*velocity;// hybrid, q & qd
|
|
|
|
qd(1) = direction*velocity;
|
|
|
|
q(2) -= direction*_ctrlComp->dt*velocity;
|
|
|
|
qd(2) = direction*velocity;
|
|
|
|
q(4) += direction*_ctrlComp->dt*velocity;// position
|
|
|
|
qd(5) = direction*1.5;// velocity
|
|
|
|
// gripper, if arm doesn't has gripper, it does noting.
|
|
|
|
gripperQ -= direction*_ctrlComp->dt*velocity;
|
2022-11-15 16:05:20 +08:00
|
|
|
Vec6 gTemp = _ctrlComp->armModel->inverseDynamics(q, qd, Vec6::Zero(), Vec6::Zero());
|
|
|
|
gTemp(0) = tau(0);
|
|
|
|
tau = gTemp;
|
2022-11-11 18:17:07 +08:00
|
|
|
sendRecv();
|
2022-07-20 11:20:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-11 18:17:07 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
2022-11-15 16:05:20 +08:00
|
|
|
std::cout << std::fixed << std::setprecision(3);
|
|
|
|
Z1ARM arm;
|
2022-11-11 18:17:07 +08:00
|
|
|
arm.sendRecvThread->start();
|
|
|
|
|
|
|
|
arm.backToStart();
|
|
|
|
arm.setFsm(ArmFSMState::PASSIVE);
|
|
|
|
arm.setFsm(ArmFSMState::LOWCMD);
|
|
|
|
|
|
|
|
std::vector<double> KP, KW;
|
|
|
|
KP = arm._ctrlComp->lowcmd->kp;
|
|
|
|
KW = arm._ctrlComp->lowcmd->kd;
|
|
|
|
|
|
|
|
// torque, only T
|
|
|
|
KP.at(0) = 0.0;
|
|
|
|
KW.at(0) = 0.0;
|
|
|
|
// position, only kp
|
|
|
|
KW.at(4) = 0.0;
|
|
|
|
// velocity, only kd
|
|
|
|
KP.at(5) = 0.0;
|
|
|
|
arm._ctrlComp->lowcmd->setControlGain(KP, KW);
|
|
|
|
arm.sendRecvThread->shutdown();
|
|
|
|
arm.runThread->start();// using runThread instead of sendRecvThread
|
|
|
|
|
|
|
|
for(int i(0); i<1000; i++){
|
2022-11-15 16:05:20 +08:00
|
|
|
// The robot arm will have vibration due to the rigid impact of the speed
|
|
|
|
// when the direction changes
|
2022-11-11 18:17:07 +08:00
|
|
|
arm.direction = i < 600 ? 1. : -1.;
|
|
|
|
usleep(arm._ctrlComp->dt*1000000);
|
2022-07-20 11:20:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-11 18:17:07 +08:00
|
|
|
arm.runThread->shutdown();
|
|
|
|
arm.sendRecvThread->start();
|
2022-07-20 11:20:01 +08:00
|
|
|
|
2022-11-15 16:05:20 +08:00
|
|
|
arm.setFsm(ArmFSMState::JOINTCTRL);
|
2022-11-11 18:17:07 +08:00
|
|
|
arm.backToStart();
|
|
|
|
arm.setFsm(ArmFSMState::PASSIVE);
|
|
|
|
arm.sendRecvThread->shutdown();
|
2022-07-20 11:20:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|