RoboDK Plug-In Interface
Loading...
Searching...
No Matches
formrobotpilot.cpp
1#include "formrobotpilot.h"
2#include "ui_formrobotpilot.h"
3
4FormRobotPilot::FormRobotPilot(RoboDK *rdk, QWidget *parent) : QWidget(parent),
5 ui(new Ui::FormRobotPilot)
6{
7 // keep the pointer to RoboDK
8 RDK = rdk;
9 Robot = nullptr;
10
11 // Create the window
12 ui->setupUi(this);
13
14 // important to delete the form when we close it (free memory)
15 setAttribute(Qt::WA_DeleteOnClose);
16
17 // Make this form as a separate window
18 setWindowFlags(windowFlags() | Qt::Window);
19
20 // Use the Cartesian Tool movement by default
21 ui->radCartesianTool->click();
22
23 // Try to select the robot (updates the robot label)
24 SelectRobot();
25}
26
27FormRobotPilot::~FormRobotPilot(){
28 delete ui;
29}
30
34
36 QList<Item> all_robots = RDK->getItemList(IItem::ITEM_TYPE_ROBOT);
37 if (all_robots.length() == 0){
38 ui->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 {
44 Robot = RDK->ItemUserPick("Select a robot", IItem::ITEM_TYPE_ROBOT);
45 }
46 bool robot_is_selected = (Robot != nullptr);
47 if (robot_is_selected) {
48 ui->lblRobot->setText("Selected robot:\n" + Robot->Name());
49 } else {
50 ui->lblRobot->setText("Robot not selected");
51 }
52 return robot_is_selected;
53}
54
55
56
58 ui->btnTXn->setText("J1-");
59 ui->btnTXp->setText("J1+");
60 ui->btnTYn->setText("J2-");
61 ui->btnTYp->setText("J2+");
62 ui->btnTZn->setText("J3-");
63 ui->btnTZp->setText("J3+");
64 ui->btnRXn->setText("J4-");
65 ui->btnRXp->setText("J4+");
66 ui->btnRYn->setText("J5-");
67 ui->btnRYp->setText("J5+");
68 ui->btnRZn->setText("J6-");
69 ui->btnRZp->setText("J6+");
70}
72 ui->btnTXn->setText("Tx-");
73 ui->btnTXp->setText("Tx+");
74 ui->btnTYn->setText("Ty-");
75 ui->btnTYp->setText("Ty+");
76 ui->btnTZn->setText("Tz-");
77 ui->btnTZp->setText("Tz+");
78 ui->btnRXn->setText("Rx-");
79 ui->btnRXp->setText("Rx+");
80 ui->btnRYn->setText("Ry-");
81 ui->btnRYp->setText("Ry+");
82 ui->btnRZn->setText("Rz-");
83 ui->btnRZp->setText("Rz+");
84}
85void FormRobotPilot::on_radCartesianReference_clicked(){
87}
88
89void FormRobotPilot::on_radCartesianTool_clicked()
90{
92}
93
94void FormRobotPilot::on_radJoints_clicked()
95{
97}
98
99void FormRobotPilot::on_btnTXn_clicked(){ IncrementalMove(0, -1); }
100void FormRobotPilot::on_btnTYn_clicked(){ IncrementalMove(1, -1); }
101void FormRobotPilot::on_btnTZn_clicked(){ IncrementalMove(2, -1); }
102void FormRobotPilot::on_btnRXn_clicked(){ IncrementalMove(3, -1); }
103void FormRobotPilot::on_btnRYn_clicked(){ IncrementalMove(4, -1); }
104void FormRobotPilot::on_btnRZn_clicked(){ IncrementalMove(5, -1); }
105
106void FormRobotPilot::on_btnTXp_clicked(){ IncrementalMove(0, +1); }
107void FormRobotPilot::on_btnTYp_clicked(){ IncrementalMove(1, +1); }
108void FormRobotPilot::on_btnTZp_clicked(){ IncrementalMove(2, +1); }
109void FormRobotPilot::on_btnRXp_clicked(){ IncrementalMove(3, +1); }
110void FormRobotPilot::on_btnRYp_clicked(){ IncrementalMove(4, +1); }
111void FormRobotPilot::on_btnRZp_clicked(){ IncrementalMove(5, +1); }
112
113
114void FormRobotPilot::IncrementalMove(int id, double sense){
115 if (!SelectRobot()) { return; }
116
117 // Calculate the relative movement
118 double step = sense * ui->spnStep->value();
119
120 // check if it is a joint movement or a Cartesian movement
121 bool is_joint_move = ui->radJoints->isChecked();
122 if (is_joint_move){
123 tJoints joints = Robot->Joints();
124 if (id >= joints.Length()){
125 qDebug() << "Internal problem: Invalid joint ID";
126 return;
127 }
128 joints.Data()[id] = joints.Data()[id] + step;
129 bool can_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){
136 qDebug()<< "Internal problem: Invalid id provided for an incremental move";
137 return;
138 }
139
140 // apply to XYZWPR
141 tXYZWPR xyzwpr;
142 for (int i=0; i<6; i++){
143 xyzwpr[i] = 0;
144 }
145 xyzwpr[id] = step;
146
147 Mat pose_increment;
148 pose_increment.FromXYZRPW(xyzwpr);
149
150 // get the current robot pose
151 Mat pose_robot = Robot->Pose();
152
153 Mat pose_robot_new;
154
155 bool is_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
159 pose_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 Mat transformation_axes(pose_robot);
167 transformation_axes.setPos(0, 0, 0);
168 Mat movement_pose_aligned = transformation_axes.inv() * pose_increment * transformation_axes;
169 pose_robot_new = pose_robot * movement_pose_aligned;
170 }
171
172 bool canmove = 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->Render();
183}
184
185
186
187
188void FormRobotPilot::on_chkRunOnRobot_clicked(bool checked){
189 if (checked) {
190 if (!SelectRobot()) {
191 RDK->ShowMessage(tr("Select a robot first"), false);
192 ui->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();
201 Robot->Joints(); // this will retrieve the joints from the real robot if connection was successful (it should be at this point)
202 RDK->Render();
203 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);
204
205 } else {
207 RDK->ShowMessage(tr("Run Mode set to simulate"), false);
208 }
209}
void IncrementalMove(int id, double sense)
IncrementalMove.
void setup_btn_joints()
Set the jog button text as joint movements.
Item Robot
Pointer to the robot that we are piloting.
RoboDK * RDK
Pointer to the RoboDK interface.
void setup_btn_cartesian()
Set the jog button text as Cartesian movement.
bool SelectRobot()
Select a robot in the Robot variable.
void on_btnSelectRobot_clicked()
Select a robot (useful if you have more than one robot in your station)
@ 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
@ 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 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...
virtual void Render(int flags=RenderComplete)=0
Update the scene.
The Joints class represents a joint position of a robot (robot axes).
Definition joints.h:51
int Length() const
Number of joint axes of the robot (or degrees of freedom)
Definition joints.cpp:140
double * Data()
Definition joints.cpp:135
The Matrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition matrix4x4.h:70
void FromXYZRPW(const double *xyzwpr)
Calculates this matrix from the position and euler angles ([x,y,z,r,p,w] vector).