RoboDK Plug-In Interface
formrobotpilot.cpp
1 #include "formrobotpilot.h"
2 #include "ui_formrobotpilot.h"
3
4FormRobotPilot::FormRobotPilot(RoboDK*rdk, QWidget *parent) : QWidget(parent),
5ui(new Ui::FormRobotPilot)
6{
7 // keep the pointer to RoboDK
8RDK = rdk;
9Robot =nullptr;
10
11 // Create the window
12ui->setupUi(this);
13
14 // important to delete the form when we close it (free memory)
15setAttribute(Qt::WA_DeleteOnClose);
16
17 // Make this form as a separate window
18setWindowFlags(windowFlags() | Qt::Window);
19
20. // Use the Cartesian Tool movement by default
21ui->radCartesianTool->click();
22
23 // Try to select the robot (updates the robot label)
24SelectRobot();
25}
26
27FormRobotPilot::~FormRobotPilot(){
28 deleteui;
29}
30
33}
34
36QList all_robots =RDK->getItemList(IItem::ITEM_TYPE_ROBOT);
37 if(all_robots.length() == 0){
38ui->lblRobot->setText("Load a robot");
39 RDK->ShowMessage("Select File-Open to load a robot or a RoboDK station",false);
40 //QString file = QFileDialog::getOpenFilename()
41 //RDK->AddFile()
42 return false;
43}else{
45}
46 boolrobot_is_selected = (Robot!=nullptr);
47 if(robot_is_selected) {
48ui->lblRobot->setText("Selected robot:\n"+Robot->Name());
49}else{
50ui->lblRobot->setText("Robot not selected");
51}
52 returnrobot_is_selected;
53}
54
55
56
58ui->btnTXn->setText("J1-");
59ui->btnTXp->setText("J1+");
60ui->btnTYn->setText("J2-");
61ui->btnTYp->setText("J2+");
62ui->btnTZn->setText("J3-");
63ui->btnTZp->setText("J3+");
64ui->btnRXn->setText("J4-");
65ui->btnRXp->setText("J4+");
66ui->btnRYn->setText("J5-");
67ui->btnRYp->setText("J5+");
68ui->btnRZn->setText("J6-");
69ui->btnRZp->setText("J6+");
70}
72ui->btnTXn->setText("Tx-");
73ui->btnTXp->setText("Tx+");
74ui->btnTYn->setText("Ty-");
75ui->btnTYp->setText("Ty+");
76ui->btnTZn->setText("Tz-");
77ui->btnTZp->setText("Tz+");
78ui->btnRXn->setText("Rx-");
79ui->btnRXp->setText("Rx+");
80ui->btnRYn->setText("Ry-");
81ui->btnRYp->setText("Ry+");
82ui->btnRZn->setText("Rz-");
83ui->btnRZp->setText("Rz+");
84}
85 无效FormRobotPilot::on_radCartesianReference_clicked(){
87}
88
89 无效FormRobotPilot::on_radCartesianTool_clicked()
90{
92}
93
94 无效FormRobotPilot::on_radJoints_clicked()
95{
97}
98
99 无效FormRobotPilot::on_btnTXn_clicked(){IncrementalMove(0, -1); }
100 无效FormRobotPilot::on_btnTYn_clicked(){IncrementalMove(1, -1); }
101 无效FormRobotPilot::on_btnTZn_clicked(){IncrementalMove(2, -1); }
102 无效FormRobotPilot::on_btnRXn_clicked(){IncrementalMove(3, -1); }
103 无效FormRobotPilot::on_btnRYn_clicked(){IncrementalMove(4, -1); }
104 无效FormRobotPilot::on_btnRZn_clicked(){IncrementalMove(5, -1); }
105
106 无效FormRobotPilot::on_btnTXp_clicked(){IncrementalMove(0, +1); }
107 无效FormRobotPilot::on_btnTYp_clicked(){IncrementalMove(1, +1); }
108 无效FormRobotPilot::on_btnTZp_clicked(){IncrementalMove(2, +1); }
109 无效FormRobotPilot::on_btnRXp_clicked(){IncrementalMove(3, +1); }
110 无效FormRobotPilot::on_btnRYp_clicked(){IncrementalMove(4, +1); }
111 无效FormRobotPilot::on_btnRZp_clicked(){IncrementalMove(5, +1); }
112
113
114 无效 FormRobotPilot::IncrementalMove(int id,doublesense){
115 if(!SelectRobot()) {return; }
116
117 // Calculate the relative movement
118 doublestep = sense * ui->spnStep->value();
119
120 // check if it is a joint movement or a Cartesian movement
121 boolis_joint_move = ui->radJoints->isChecked();
122 if(is_joint_move){
123 tJointsjoints =Robot->Joints();
124 if(id>= joints.Length()){
125qDebug() <<"Internal problem: Invalid joint ID";
126 return;
127}
128joints.Data()[id] = joints.Data()[id] + step;
129 boolcan_move =Robot->MoveJ(joints);
130 if(!can_move){
131 RDK->ShowMessage(tr("The robot can't move to this location"),false);
132}
133}else{
134 // check the index so that is is within 0-5
135 if(id < 0 || id >= 6){
136qDebug()<<"Internal problem: Invalid id provided for an incremental move";
137 return;
138}
139
140 // apply to XYZWPR
141tXYZWPR xyzwpr;
142 for(inti=0; i<6; i++){
143xyzwpr[i] = 0;
144}
145xyzwpr[id] = step;
146
147 Matpose_increment;
148pose_increment.FromXYZRPW(xyzwpr);
149
150 // get the current robot pose
151 Matpose_robot =Robot->Pose();
152
153 Matpose_robot_new;
154
155 boolis_tcp_relative_move = ui->radCartesianTool->isChecked();
156 if(is_tcp_relative_move){
157 // apply relative to the TCP:
158 // if the movement is relative to the TCP we must POST MULTIPLY the movement
159pose_robot_new = pose_robot * pose_increment;
160}else{
161 // it is a movement relative to the reference frame
162 // if the movement is relative to the reference frame we must PRE MULTIPLY the XYZ translation:
163 // new_robot_pose = movement_pose * robot_pose;
164 // Note: Rotation applies from the robot axes.
165
166 Mattransformation_axes(pose_robot);
167transformation_axes.setPos(0, 0, 0);
168 Matmovement_pose_aligned = transformation_axes.inv() * pose_increment * transformation_axes;
169pose_robot_new = pose_robot * movement_pose_aligned;
170}
171
172 boolcanmove =Robot->MoveJ(pose_robot_new);
173 if(!canmove){
174 RDK->ShowMessage(tr("The robot can't move to this location"),false);
175}
176 /*if (!Robot->setPose(pose_robot_new)){
177 RDK->ShowMessage("The robot can not reach the requested position!", false);
178 }*/
179}
180
181 // This is very important to update robot joints and force a display RoboDK
182 RDK->渲染();
183}
184
185
186
187
188 无效FormRobotPilot::on_chkRunOnRobot_clicked(boolchecked){
189 if(checked) {
190 if(!SelectRobot()) {
191 RDK->ShowMessage(tr("Select a robot first"),false);
192用户界面- > chkRunOnRobot - > setChecked(false);
193 return;
194}
195 /*if (!){
196 RDK->ShowMessage(tr("Robot not connected! Select Connect->Connect Robot and enter the IP"), false);
197 return;
198 }*/
199 Robot->Connect();
20.1 Robot->Joints();// this will retrieve the joints from the real robot if connection was successful (it should be at this point)
20.2 RDK->渲染();
20.3 RDK->ShowMessage(tr("Run Mode set to run the real robot. Make sure you are properly connected to the robot (select Connect-Connect Robot)"),false);
20.4
20.5}else{
20.7 RDK->ShowMessage(tr("Run Mode set to simulate"),false);
20.8}
20.9}
无效IncrementalMove(int id, double sense)
IncrementalMove.
无效setup_btn_joints()
Set the jog button text as joint movements.
Definition: formrobotpilot.cpp:57
Item Robot
Pointer to the robot that we are piloting.
Definition: formrobotpilot.h:74
RoboDK * RDK
Pointer to the RoboDK interface.
Definition: formrobotpilot.h:71
无效setup_btn_cartesian()
Set the jog button text as Cartesian movement.
Definition: formrobotpilot.cpp:71
bool SelectRobot()
Select a robot in the Robot variable.
Definition: formrobotpilot.cpp:35
无效on_btnSelectRobot_clicked()
Select a robot (useful if you have more than one robot in your station)
Definition: formrobotpilot.cpp:31
@ ITEM_TYPE_ROBOT
Item of type robot (.robot file)
Definition: iitem.h:26
virtual QString Name()=0
Returns the name of an item. The name of the item is always displayed in the RoboDK station tree
virtual bool MoveJ(const Item &itemtarget)=0
Add a joint move to a program or move a robot to a target item ("Move Joint" mode)....
virtual Mat Pose()=0
Returns the local position (pose) of an object, target or reference frame. For example,...
virtual bool Connect(const QString &robot_ip="")=0
Connect to a real robot using the corresponding robot driver.
virtual tJoints Joints()=0
Returns the current joints of a robot or the joints of a target. If the item is a cartesian target,...
This class is the iterface to the RoboDK API. With the RoboDK API you can automate certain tasks and ...
Definition: irobodk.h:14
virtual Item ItemUserPick(const QString &message="Pick one item", int itemtype=-1)=0
Shows a RoboDK popup to select one object from the open RoboDK station. An item type can be specified...
virtual void ShowMessage(const QString &message, bool popup=true)=0
Show a message in RoboDK (it can be blocking or non blocking in the status bar)
virtual void setRunMode(int run_mode=1)=0
Sets the behavior of the RoboDK API. By default, RoboDK shows the path simulation for movement instru...
virtual QList< Item > getItemList(int filter=-1)=0
Returns a list of items (list of names or pointers) of all available items in the currently open stat...
@ RUNMODE_RUN_ROBOT
Moves the real robot from the PC (PC is the client, the robot behaves like a server).
Definition: irobodk.h:94
@ RUNMODE_SIMULATE
Performs the simulation moving the robot (default)
Definition: irobodk.h:79
virtual void Render(int flags=RenderComplete)=0
Update the scene.
Mat
The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in...
Definition: robodktypes.h:361
无效FromXYZRPW(tXYZWPR xyzwpr)
Calculates the pose from the position and euler angles ([x,y,z,r,p,w] vector) The result is the same ...
Definition: robodktypes.cpp:475
Mat inv() const
Invert the pose (homogeneous matrix assumed)
Definition: robodktypes.cpp:305
无效setPos(double x, double y, double z)
Set the position (T position) in mm.
Definition: robodktypes.cpp:239
The tJoints class represents a joint position of a robot (robot axes).
Definition: robodktypes.h:239
int Length() const
Number of joint axes of the robot (or degrees of freedom)
Definition: robodktypes.cpp:123
double * Data()
Definition: robodktypes.cpp:73