Pendulum with simple FOC control

HI Guys:
I am making a same pendulum as the simple foc examples:
Screenshot 2021-02-06 144142
but there is something wrong with my pendulum when i testing it.
i used 2 as5600 to replace the encoder, and both of them used I2C port. and to keep the weight as close as possible to the example, i fixed 2 batterys on the wheel(it costs too much time if set infill 70% with 3d printer)…
when i run the motor, the pendulum always run over the stable position, and seems never goona stop circuling… below is my test video.

pendulum with simple foc

if i grab the arm of pendulum, and try different angle of the pendulum, i can found that the steady postion is not the 90 degree standing position, but about 45 degree away from the stand.
i was wondering if it has any connection with as5600’s absolut position ? the controller take the absolute positon as the beginning postion?

By the way, anybody can share that if my wheel’s weight is different from example, how to change the the target_voltage to adapt to the weight?

target_voltage = -_sign(pendulum.getVelocity())*motor.voltage_limit*0.4;

Anyone knows how to insert a video in the page, instead of a hyperlink? :cry:

For videos to be embedded not linked, you need to not link to it. I.e simple paste the url into your post. It works for youtube, not sure if it’ll work for youku.

This is @Antun_Skuric project right? Looks like you are really close to getting this working! My guess is that 0.4 is a constant that you need to tune.

Hey @zdldcyy,

I like your setup. Yes so the absolute sensor value is used for motor control but in the case of the pendulum you can get around it.
In your setup function add something like:

float zero_offset = 0;
zero_offset = pendulum_sensor.getAngle();

and each time you read the pendulum angle you subtract the zero_offset.
Just make sure to keep the pendulum facing down on the beginning.

I don’t remember the weight any more but it should be more or less as yours with batteries. you can tweak this 0.4 number to get better performance. There are also other algorithms to do this more optimally, this one is really simple.

I would suggest you to stabilize the pendulum fist and make sure it works and then to try to tweak the swing-up parameters.

And also, try fix the pendulum a bit more sturdy for now until you have good results.

hi @Antun_Skuric
thank you for quick response, with your suggestion, i have fixed the problem now :grin:
And as you suggestted, i really need to strengthen my pendulum, it almost broken when crushing down :joy:

1 Like

Now I try to make similar balancer but using drv8302 and 5010 motor. How can I calculate LQR constants for this system. Kinematic sheme like Antur but different sizes and masses.