maybe with an example you’ll have a better vision of what I want to do.
below is the struccture of the programm I have (its the script generated by polyscope in wich I only left the necessary thing for you to understand). basicaly in my main I can call 2 subprogramm each corresponding to a task. the to task are very similar : I take a screw in a fixed location and I screw it on a part. i do this 3 time in each task.
actual programm :
def V411_15062016_vissage():
def Traj4CycleT9():
#code to pick a screw
write_port_register(253,9)
write_port_register(252,0)
write_port_register(250,0)
movej([-2.9521238992230607, -1.292814290267251, 1.9908212812675723, -0.7104551804888581, 1.162431877157648, 0.020028483285286003], a=7.853981633974483, v=2.0943951023931953, r=0.02)
movej([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=7.853981633974483, v=2.0943951023931953)
write_port_register(250,1)
movel([-2.9519790571130264, -1.1782730282822786, 2.041176717344804, -0.8755353908661654, 1.1624436251818802, 0.020492227300552], a=1.2, v=0.6)
sleep(0.4)
movel([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=1.2, v=0.6)
write_port_register(252,1)
movel([-2.948840546689379, -1.2844094640353863, 1.9933263102643721, -0.7213601063809145, 1.1657042364710628, 0.020015619302867833], a=1.2, v=0.6)
movej([-3.1931641852177712, -1.2582465030249672, 1.9114467716248864, -0.6487440713726791, -0.0316149869218636, 0.024403496840181838], a=7.853981633974483, v=2.0943951023931953, r=0.01)
movej([-3.4264179477612373, -0.6840110642992485, 1.1596317820044977, -0.4197711643286315, -0.3224758348089516, -0.015732572371568665], a=7.853981633974483, v=2.0943951023931953)
#end of the ‘pick a screw’ section
#screwing 1
movej([-3.2802634921321534, -0.9317892237464918, 1.6489983629403948, -0.6860787335585412, 2.242125980447158, 0.010818009529581118], a=7.853981633974483, v=2.0943951023931953)
movel([-3.2801755528893954, -0.8620241589456983, 1.6639969269169772, -0.7706593111618218, 2.2421713247055792, 0.011111676566495617], a=1.2, v=0.8)
sleep(0.1)
#code to pick a screw
write_port_register(253,9)
write_port_register(252,0)
write_port_register(250,0)
movej([-2.9521238992230607, -1.292814290267251, 1.9908212812675723, -0.7104551804888581, 1.162431877157648, 0.020028483285286003], a=7.853981633974483, v=2.0943951023931953, r=0.02)
movej([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=7.853981633974483, v=2.0943951023931953)
write_port_register(250,1)
movel([-2.9519790571130264, -1.1782730282822786, 2.041176717344804, -0.8755353908661654, 1.1624436251818802, 0.020492227300552], a=1.2, v=0.6)
sleep(0.4)
movel([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=1.2, v=0.6)
write_port_register(252,1)
movel([-2.948840546689379, -1.2844094640353863, 1.9933263102643721, -0.7213601063809145, 1.1657042364710628, 0.020015619302867833], a=1.2, v=0.6)
movej([-3.1931641852177712, -1.2582465030249672, 1.9114467716248864, -0.6487440713726791, -0.0316149869218636, 0.024403496840181838], a=7.853981633974483, v=2.0943951023931953, r=0.01)
movej([-3.4264179477612373, -0.6840110642992485, 1.1596317820044977, -0.4197711643286315, -0.3224758348089516, -0.015732572371568665], a=7.853981633974483, v=2.0943951023931953)
#end of the ‘pick a screw’ section
#screwing 2
write_port_register(250,0)
write_port_register(253,17)
movej([-3.239982493934226, -0.8046736568395891, 1.4043026328938741, -0.5792104342181457, 2.3474051197208663, 0.018987783387459586], a=7.853981633974483, v=1.7453292519943295, r=0.005)
movel([-3.2423827803166, -0.7546684269553543, 1.4247645630890724, -0.6494878094437144, 2.344958777680449, 0.01921326244165306], a=1.2, v=0.8)
#code to pick a screw
write_port_register(253,9)
write_port_register(252,0)
write_port_register(250,0)
movej([-2.9521238992230607, -1.292814290267251, 1.9908212812675723, -0.7104551804888581, 1.162431877157648, 0.020028483285286003], a=7.853981633974483, v=2.0943951023931953, r=0.02)
movej([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=7.853981633974483, v=2.0943951023931953)
write_port_register(250,1)
movel([-2.9519790571130264, -1.1782730282822786, 2.041176717344804, -0.8755353908661654, 1.1624436251818802, 0.020492227300552], a=1.2, v=0.6)
sleep(0.4)
movel([-2.9520251733431686, -1.2427798716958822, 2.016993971769297, -0.7867436993404411, 1.1624614730974743, 0.02023417547019577], a=1.2, v=0.6)
write_port_register(252,1)
movel([-2.948840546689379, -1.2844094640353863, 1.9933263102643721, -0.7213601063809145, 1.1657042364710628, 0.020015619302867833], a=1.2, v=0.6)
movej([-3.1931641852177712, -1.2582465030249672, 1.9114467716248864, -0.6487440713726791, -0.0316149869218636, 0.024403496840181838], a=7.853981633974483, v=2.0943951023931953, r=0.01)
movej([-3.4264179477612373, -0.6840110642992485, 1.1596317820044977, -0.4197711643286315, -0.3224758348089516, -0.015732572371568665], a=7.853981633974483, v=2.0943951023931953)
#end of the ‘pick a screw’ section
#screwing 3
write_port_register(253,19)
movej([-3.2675743356874007, -0.8083154591221273, 1.4112182848032024, -0.5830337885745678, 2.3198126500374796, 0.018215456541135665], a=7.853981633974483, v=2.0943951023931953, r=0.02)
movel([-3.267512455287351, -0.7593649390138753, 1.424712412917711, -0.6453350765614356, 2.319841651519912, 0.018425638666511], a=1.2, v=0.8)
end
def Traj5CycleK0_P8():
#same structure as "Traj4CycleT9()"
end
$ 2 "AvantDémarrage"
write_port_register(241,0)
write_port_register(254,1)
sleep(0.2)
write_port_register(241,0)
while (True):
write_port_register(254,0)
movej([-3.1931641852177717, -1.2582465030249663, 1.9114467716248862, -0.6487440713726782, -0.0316149869218636, 0.024403496840181994], a=7.853981633974483, v=2.0943951023931953)
global program_number=read_port_register(138)
$ 41 "Si program_number≟4"
if (program_number == 4):
Traj4CycleT9()
movej([-3.1931641852177717, -1.2582465030249663, 1.9114467716248862, -0.6487440713726782, -0.0316149869218636, 0.024403496840181994], a=7.853981633974483, v=2.0943951023931953)
write_port_register(252,1)
end
$ 47 "Si program_number≟5"
if (program_number == 5):
Traj5CycleK0_P8()
movej([-3.1931641852177717, -1.2582465030249663, 1.9114467716248862, -0.6487440713726782, -0.0316149869218636, 0.024403496840181994], a=7.853981633974483, v=2.0943951023931953)
end
end
end