Crude actuation scheme for cylinders

Hi everyone,

I’m attempting to actuate some cylinder shapes using the following:

def update(task):
        dt = globalClock.getDt()
        world.doPhysics(dt)
        if task.time % 2 < 0.02:
            for lines in range(len(stickList) - 1):
                Stick1 = stickList[lines]
                Stick1.set_scale(2)
        else:
            for lines in range(len(stickList) - 1):
                Stick1 = stickList[lines]
                Stick1.set_scale(1)

Please advise on the method to execute a task every X seconds?

Thank you

You could use a do-later task as is described here:
https://www.panda3d.org/manual/?title=Tasks#The_Do-Later_Task

and return task.again to repeat it after the set delay at initialization

1 Like

Something like this?

def actuate(task):
    for lines in range(len(stickList) - 1):
        Stick1 = stickList[lines]
        Stick1.set_scale(2)
    return task.again

def update(task):
    dt = globalClock.getDt()
    world.doPhysics(dt)
    return task.cont

taskMgr.add(update, 'update')
taskMgr.doMethodLater(actuate, 2, 'actuate')

Is it just me or is it a little difficult for someone who is not familiar with these types of things to understand the Panda3D documentation?

Thanks for the attention

Nevermind, got it figured thanks!

Like so:

def reactuate(task):
    for lines in range(len(stickList) - 1):
        Stick1 = stickList[lines]
        Stick1.set_scale(2)
    return task.again

def deactuate(task):
    for lines in range(len(stickList) - 1):
        Stick1 = stickList[lines]
        Stick1.set_scale(1)
    return task.again

taskMgr.doMethodLater(funcOrTask=reactuate, delayTime=1, name='reactuate')
taskMgr.doMethodLater(funcOrTask=deactuate, delayTime=1.5, name='deactuate')

New question:
How do I make the constraints applicable on the “sticks” to scale with the stick?

Could you perhaps read the scale from the model (via “.getScale()”), and then just multiply the relevant constraint values by that scale, as appropriate?

[edit]
However, note this caveat in the manual: if feasible, it might be better to avoid scaling your physics elements. As long as it doesn’t clash with your intended behaviour, it might be better to simply give your physics objects an appropriate size, taking any scaling factors into account when creating them.

Thanks @Thaumaturge. How would you make the sticks actuate?

What do you mean? If you’re using Bullet, can you not just apply forces to the sticks? Or do you mean something else?

I need the sticks to elongate sort of like a hydraulic cylinder almost. The particular application will be soft robotics where the sticks will be pneumatically actuated soft robotic actuators.

Later I will also make a bending stick but I figure I’ll just use three segments with bending constraints.

Ah, I see. Hmm… Could you perhaps use two nested “sections” per hydraulic cylinder–much as I imagine the actual cylinder would function?

@Thaumaturge, could I change the height of the cylinders using something like this: https://www.panda3d.org/manual/?title=Modifying_existing_geometry_data

If so, would you be so kind as to provide some guidances for coding this using a NodePath list of created nodes to which these cylinders are attached?

Hmm… If you’re referring to changing the physics-objects, then I don’t know–I don’t know whether that’s feasible or advisable with Bullet objects.

If you’re referring to changing any visual geometry that you associate with the physics objects, then I think that you could do that, indeed. However, as long as the physics objects aren’t children of the visual objects and thus affected by changes to them, I would also think that simply scaling the visual-geometry objects might be easier.

You didn’t respond to my suggestion of using two objects per hydraulic cylinder–will that not work for extending them? (I imagine that you would use either masks or constraints to prevent them from colliding with each other.)