# -*- coding: utf-8 -*-
# Macro Begin: ...\Asm3_rotor.FCMacro +FreeCAD
#Test rotation OgiveGearWheel-Warhead (Constraint009) and Blade1-Rotor (Constraint002)
#Test rotation OgiveGearWheel-Warhead (Constraint009) et Blade1-Rotor (Constraint002)


import FreeCAD

#rotation Rotor-Base (Constraint001)
#rotation OgiveGearWheel-Warhead (Constraint009)
#rotation Blade1-Rotor (Constraint002)
#rotation Blade2-Rotor (Constraint003)
#rotation Blade3-Rotor (Constraint004)

import time #Clock to create animation   Horloge pour créer l'animation

#2nd movement : the wind is too fast, the rotor speed too high
#the centrifugal effect on the weights corrects the inclination of the blades

#locking of the angles of the blades and the toothed wheel of the ogive
#so that piloting is possible


#2nd mouvement : le vent est trop fort, la vitesse du rotor trop rapide
#l'effet centrifuge sur les masselottes corrige l'inclinaison des pales

#verrouillage des angles des pales et de la roue dentée de l'ogive
#pour rendre le pilotage possible

FreeCAD.getDocument('_Asm3_100WindTurbine').getObject('Constraint002').LockAngle = True
FreeCAD.getDocument('_Asm3_100WindTurbine').getObject('Constraint003').LockAngle = True
FreeCAD.getDocument('_Asm3_100WindTurbine').getObject('Constraint004').LockAngle = True
FreeCAD.getDocument('_Asm3_100WindTurbine').getObject('Constraint009').LockAngle = True

#definition of new variables and their starting value (to be checked and confirmed)
#for control of the rotation of the rotor, the blades and the toothed wheel of the ogive

#définition des variables et de leurs valeurs initiales (doivent être vérifiées et confirmées)
#pour contrôler la rotation du rotor, des pales et de la roue dentée de l'ogive

angle1 = 12      #variable for rotation OgiveGearWheel-Warhead (Constraint009)
angleBl1 = 12    #variable for rotation Blade1-Rotor (Constraint002)
angleBl2 = 12    #variable for rotation Blade2-Rotor (Constraint003)
angleBl3 = -12   #variable for rotation Blade3-Rotor (Constraint004)


#Set in motion with rotation OgiveGearWheel-Warhead (Constraint009) and Blade1-Rotor (Constraint002) only
#Mise en mouvement avec OgiveGearWheel-Warhead (Constraint009) and rotation Blade1-Rotor (Constraint002) seulement

for i in range(41):
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint009").Angle = angle1
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint002").Angle = angleBl1
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint003").Angle = angleBl2
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint004").Angle = angleBl3
    Gui.runCommand('asm3CmdQuickSolve',0)
    angle1 += 0.5
    angleBl1 += 1
    angleBl2 += 1
    angleBl3 -= 1
    FreeCADGui.updateGui() # necessary to update the screen before each incrementation
    time.sleep(0.001)

#Back movements
#Mouvements de retour
for i in range(42):
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint009").Angle = angle1
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint002").Angle = angleBl1
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint003").Angle = angleBl2
    FreeCAD.getDocument("_Asm3_100WindTurbine").getObject("Constraint004").Angle = angleBl3
    Gui.runCommand('asm3CmdQuickSolve',0)
    angle1 -= 0.5
    angleBl1 -= 1
    angleBl2 -= 1
    angleBl3 += 1
    FreeCADGui.updateGui() # necessary to update the screen before each incrementation
    time.sleep(0.001)


# Macro End:  +++
