I’ve got dynamixel SDK python scripts that open a port to a smart servo motor over serial:
dynamixel.openPort(1)
then I want to send out a motor goal position every frame, but I don’t want to open/close port again. I want to keep the port open until I don’t.
dynamixel.write2ByteTxRx(1,2,3,n)
IM assuming i want to write a script in chopExecute or Execute DAT that will allow me to change variable ‘n’. But I don’t understand the basic structure of this scripting. I need an example. Im guessing I turn ‘value change’ toggle on, but where in script does openPort command need to live so it executes only once ?
basically how do i write a script that will open the port once, then change ‘n’ 30fps.
then close the port manually when I want ?
Sounds like you might start by making a toggle button that calls the connect when turned on and disconnect when turned off. Use the panel exec DAT to write callbacks onOffToOn and onOnToOff…
As for sending the values at 30fps there are a few ways, but a simple one is to use executeDAT’s onFrameStart and set the project fps to 30.
Your onToOff/offToOn code makes sense looking at the CHOP output of the button. The valueChange callback will only be called when the button’s value changes and it looks like you want to send those write2ByteTxRx messages every frame. To do that use the onFrameEnd callback in an executeDAT. That callback will run every frame. And if you need to run at 30fps, you can set that in the bottom left area of the editor by the timeline.
An alternative to using Execute DAT is using a Chop Execute DAT on op(‘null1’) and using the onValueChange callback. That will get called every time the CHOP changes
channel is the CHOP channel whose value changed
sampleIndex is which sample changed (only for multisample CHOPs)
val is the value the channel changed to
prev is the previous value of the channel
I guess I’m not sure exactly how your network is set up, so my suggestions might not make sense. Feel free to attach a tox or toe.
ok so I am not clear on the callbacks scripting structure here still.
My intent:
‘v1’ and ‘LED’ trigger 2 different actions when either one goes offToOn.
I scripted ‘v1’ to open/close port, but how now in the same script to turn ‘LED’ off/on ?
‘variable1’ and ‘variable2’ trigger 2 different actions when either value changes.
What does the script look like ? I’m not sure how to construct this in one CHOPexecuteDAT… Chopex1.3.toe (4.9 KB)