Maybe it is a trival question, but I don’t know whether there is a simpler way to launch distinct scripts on buttons click. For example I’d like to record the robot motion after clicking record_button
(until a stop_record_button
is pressed), and playback the same trajectory everytimes a play_button
button is clicked.
A very simple code of the above example:
@Input(id = "record_button")
public void onRecordButtonClick(InputEvent event) {
if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
record_phase = true;
}
}
@Input(id = "stop_record_button")
public void onRecordButtonClick(InputEvent event) {
if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
record_phase = false;
}
}
@Input(id = "play_button")
public void onRecordButtonClick(InputEvent event) {
if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
play_phase = true;
}
}
...
@Override
public void generateScript(ScriptWriter writer) {
while (true) {
if (record_phase) {
writer.appendLine("teach_mode()");
while (record_phase) {
// store current joint positions
// sleep for N ms
}
}
if (stop_record_phase) {
writer.appendLine("end_teach_mode()");
// adjust trajectory in M waypoints
}
if (play_phase) {
// follow the stored trajectory
play_phase = false;
}
}
}
Can the switch behavior of the generateScript
be avoided in someway?
Alessandro Tondo @qbrobotics
Update: moreover I’m facing out with the fact that get_actual_joint_positions()
is a script function and I’m not able to get its return inside my ProgramContribution. Also, I don’t want to have my PC connected to the robot all the time, so I was wondering whether the xmlrpc is the only way to elaborate these data or there is a simpler choice (I think I cannot do the computation directly inside my script since I need a “matrix” variable to store the poses over time).
Update2: I’m sorry for the many nested questions but I’ve noted that there is no way to interact with a URCap while the program is running, i.e. if I click on any button the execution immediately stops. Is it right?