Servo.detach() Published event

Hi ! someone know how can I intercept a detach() action of a servo .
If not possible is it possible to implement a Published detach information ?

Because I use servo they didn't detach via pwm ( I use a relay to micro shutdown +6v )
And don't want to add multiple non standardized line in script

Thanks
 

GroG's picture

Hi Moz4r, The script is the

Hi Moz4r,
The script is the most non-standard thing there is.

As far as intercepting the detach - yes you can if it's invoked, and if its called by another service, there is a good chance its invoked.

If it is invoked you just need to subscribe to it.

Hope this makes sense.

When and what exactly is being detached ?

moz4r's picture

Hi Grog ! I use some servo

Hi Grog ! I use some servo they won't detach  ( impossible because internal security )
So I send a command to enable a pin of the arduino ( pin that control a relay )

when I want to detach a servo to prevent fireing the house , I use this piece of code ,

servo.detach() // mrl command to shutdown pwm
+
left
.pinMode(51, Arduino.OUTPUT)
sleep(0.1)
left.digitalWrite(53,255)
left.digitalWrite(51,255)
sleep(0.1)
left.digitalWrite(53,0)
left.digitalWrite(51,0)
 
What do you think about a good solution inside mrl or script ?

 

moz4r's picture

thank you , I can now use

thank you , I can now use official servo.detach() command !

python.subscribe(i01.leftArm.bicep.getName(),"publishServoDetach")
python.subscribe(i01.leftArm.rotate.getName(),"publishServoDetach")
python.subscribe(i01.leftArm.bicep.getName(),"publishServoAttach")
python.subscribe(i01.leftArm.rotate.getName(),"publishServoAttach")

def onServoDetach(data):
    print data
    relayAction(left,53,255)
    
    
def onServoAttach(data):
    print data
    relayAction(left,53,0)
    
    
def relayAction(ard,pin,value):
    print value
    ard.pinMode(pin, Arduino.OUTPUT)
    ard.digitalWrite(pin,value)
    
  
i01.leftArm.detach()    
sleep(5)
i01.leftArm.attach()