Skip to content

Commit 0648b18

Browse files
committed
V2.2.6 add gripper tau limit interface
1 parent fd5a63f commit 0648b18

File tree

11 files changed

+125
-5
lines changed

11 files changed

+125
-5
lines changed

config/config.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
<limitT>10.0</limitT> <!-- N*M -->
99
<load>0.0</load><!-- kg-->
1010
</collision>
11+
12+
<grasp_max_torque>10.0</grasp_max_torque>
1113
</configurartion>

include/FSM/FSMState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "common/math/mathTools.h"
99
#include "common/utilities/timer.h"
1010
#include "FSM/BaseState.h"
11+
#include "model/unitree_gripper.h"
1112

1213
class FSMState : public BaseState{
1314
public:
@@ -25,11 +26,13 @@ class FSMState : public BaseState{
2526
void _recordData();
2627
Vec6 _postureToVec6(Posture posture);
2728
void _tauFriction();
29+
void _zero_position_joint4_protection();
2830

2931
LowlevelCmd *_lowCmd;
3032
LowlevelState *_lowState;
3133
IOInterface *_ioInter;
3234
ArmModel *_armModel;
35+
std::shared_ptr<Unitree_Gripper> _gripper;
3336

3437
Vec6 _qPast, _qdPast, _q, _qd, _qdd, _tauForward;
3538
double _gripperPos, _gripperW, _gripperTau;

include/FSM/State_Cartesian.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class State_Cartesian : public FSMState{
1616
double _posSpeed = 0.2;
1717
double oriSpeedLimit = 0.5;// limits in SDK
1818
double posSpeedLimit = 0.5;
19-
VecX _changeDirections;
19+
VecX _changeDirectionsf;
2020

2121
Vec6 _twist;
2222
HomoMat _endHomoGoal, _endHomoPast, _endHomoDelta;

include/control/CtrlComponents.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "interface/IOUDP.h"
1313
#include "interface/IOROS.h"
1414
#include "control/armSDK.h"
15+
#include "model/unitree_gripper.h"
1516

1617
using namespace std;
1718

@@ -25,6 +26,7 @@ struct CtrlComponents{
2526
IOInterface *ioInter;
2627
Z1Model *armModel;
2728
CSVTool *stateCSV;
29+
std::shared_ptr<Unitree_Gripper> gripper;
2830

2931
SendCmd sendCmd; // cmd that receive from SDK
3032
RecvState recvState;// state that send to SDK

include/control/armSDK.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
class ARMSDK : public CmdPanel{
88
public:
99
ARMSDK(std::vector<KeyAction*> events,
10-
EmptyAction emptyAction, const char* IP, uint toport, uint ownport, double dt = 0.002);
10+
EmptyAction emptyAction, const char* IP, uint port, double dt = 0.002);
1111
~ARMSDK();
1212
SendCmd getSendCmd();
1313
int getState(size_t channelID = 0);
1414
void setRecvState(RecvState& recvState);
15+
void start();
1516
private:
1617
void _sendRecv();
1718
void _read(){};

include/control/cmdPanel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ValueAction : public KeyAction{
7676
double _dV = 0.0; //delta value per delta time
7777
double _dt = 0.0;
7878
double _dVdt = 0.0; // delta value per second
79-
double _dVdtf = 0.0; // delta value per second after filter
79+
double _dVdtf = 0.0; // delta value per second after fliter
8080
double _lim1, _lim2;
8181
bool _hasLim = false;
8282
bool _hasGoZero = false;
@@ -104,6 +104,7 @@ class CmdPanel{
104104
virtual std::vector<std::vector<double> > stringToMatrix(std::string slogan);
105105
virtual SendCmd getSendCmd();
106106
virtual void setRecvState(RecvState& recvState){};
107+
void start(){_runThread->start();}
107108
protected:
108109
virtual void _read() = 0;
109110
void _run();

include/model/unitree_gripper.h

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#ifndef _UNITREE_GRIPPER_H
2+
#define _UNITREE_GRIPPER_H
3+
4+
#include <algorithm>
5+
#include <cmath>
6+
#include <chrono>
7+
#include "common/math/mathTools.h"
8+
9+
typedef struct
10+
{
11+
double angle; // Current gripper opening angle. Unit: rad
12+
double speed; // Current measured gripper speed. Unit: rad/s
13+
double tau; // Current measured gripper output torque. Unit: Nm
14+
bool is_grasped; // Indicates whether an object is currently grasped.
15+
int8_t temperature; // current temperature (temperature conduction is slow that leads to lag)
16+
}GripperState;
17+
18+
typedef struct
19+
{
20+
double angle; // Size of object to grasp in radian
21+
double speed; // Closing speed in rad/s
22+
double tau; // Grasping tau in Nm
23+
double epsilon_inner; // Maximum tolerated deviation when the actual grasped angle is smaller than the commanded grasp angle.
24+
double epsilon_outer; // Maximum tolerated deviation when the actual grasped angle is larger than the commanded grasp angle.
25+
}GripperCmd;
26+
27+
class Unitree_Gripper
28+
{
29+
public:
30+
Unitree_Gripper();
31+
Unitree_Gripper(double max_toque);
32+
~Unitree_Gripper() = default;
33+
34+
/**
35+
* @brief Move the gripper to target angle
36+
*
37+
* @param angle Target opening angle in rad
38+
* @param speed Opening speed in rad/s
39+
*/
40+
void move(double angle, double speed);
41+
42+
/**
43+
* @brief Grasps an object
44+
*
45+
* @param angle Size of object to grasp in radian.
46+
* @param speed Closing speed in rad/s.
47+
* @param tau Grasping torque in Nm
48+
* @param epsilon_inner Maximum tolerated deviation when the actual grasped angle
49+
* is smaller than the commanded grasp angle.
50+
* @param epsilon_outer Maximum tolerated deviation when the actual grasped angle
51+
* is larger than the commanded grasp angle.
52+
* @return True if an object has been grasped.
53+
*/
54+
void grasp( double angle,
55+
double speed,
56+
double tau,
57+
double epsilon_inner = 0.01,
58+
double epsilon_outer = 0.01);
59+
60+
/**
61+
* @brief Get current output torque due to current state
62+
*
63+
* @param angle Measured gripper angle
64+
* @param speed Measured gripper speed
65+
* @param torque Measured gripper torque
66+
* @param temperature Measured gripper temperature
67+
* @return double Output torque
68+
*/
69+
double update(double angle, double speed, double torque, int8_t temperature = 0);
70+
71+
GripperCmd cmd{};
72+
GripperState state{};
73+
private:
74+
enum class GripperCtrlMode{
75+
Move,// Position
76+
Grasp// Torque
77+
} mode = GripperCtrlMode::Move;
78+
79+
struct
80+
{
81+
double kp_p;
82+
double kd_p;
83+
double kp_v;
84+
double ki_v;
85+
double kd_v;
86+
} coe{};
87+
88+
typedef struct
89+
{
90+
double angle;
91+
double speed;
92+
} Error_state;
93+
94+
Error_state error{}, error_last{};
95+
double error_speed_sum_{};
96+
97+
static constexpr double MAX_POSITION = -M_PI/2;
98+
static constexpr double MAX_SPEED = M_PI;
99+
double MAX_TORQUE = 20.0;
100+
101+
std::chrono::steady_clock::time_point first_grasped_time_{};
102+
bool is_stopped_{};
103+
double tau_output{};
104+
105+
void modify_cmd(GripperCmd& gripper_cmd);
106+
bool is_grasped();
107+
};
108+
109+
#endif // _UNITREE_GRIPPER_H

lib/libZ1_ROS_x86_64.so

15.7 KB
Binary file not shown.

lib/libZ1_UDP_aarch64.so

100644100755
-214 KB
Binary file not shown.

lib/libZ1_UDP_x86_64.so

15.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)