Copy and paste the following job into DDE and read and follow the directions below
function example_4_init(){
let CMD = []
CMD.push(Dexter.move_all_joints([0, 0, 0, 0, 0]))
return CMD
}
function example_4_main(){
return Robot.loop(true, function(){
let CMD = []
CMD.push(Dexter.move_all_joints([-15, 0, 0, 0, 0]))
CMD.push(Dexter.move_all_joints([15, 0, 0, 0, 0]))
CMD.push(Dexter.empty_instruction_queue())
return CMD
})
}
new Job({
name: "Example_4",
keep_history: true,
show_instructions: true,
inter_do_item_dur: 0,
user_data: {},
do_list: [
example_4_init,
example_4_main
]
})
/*
To Run:
Eval and run the Job.
Click the Job button again to stop it.
-How many times example_4_init is run
-How many times example_4_main is run
-The position Dexter ends up in in when the Job is stopped
(no matter when you stop it)
Edit the above code in order to do the following:
a. Have Dexter move its J1 to 15 degrees before starting the loop.
b. Only run the loop 10 times.
c. Make a user_data variable named 'count'. Set count to the number of times
the loop code has been run, even if the Job is stopped prematurely.
Example 4 is an example of a very common code structure:
Run this chunk of code once at the beginning to set everything
up
Then
Run this chunk of code over and over forever until I tell it to stop
The majority of the code I write for clients and internal projects starts of with the code in Example 4 as a template.
The first argument of Robot.loop is set to true.
This means that it will loop forever or at least until the stop button is
clicked.
There are few different things that can go into this first argument.
See the DDE documentation on Robot.loop by placing the cursor on 'loop' then click the blue underlined 'Robot.loop' in the Output pane to auto-scroll the Doc pane to it.