rencheckyoself / self-balancing-robot

ROS-based simulation and prototyping of a self balancing robot.
4 stars 1 forks source link

About the SolverEom and service start #1

Closed AkhilAsok11 closed 7 months ago

AkhilAsok11 commented 7 months ago

Screenshot from 2024-04-06 14-44-56

Even after running the solverEOM for 3 hours it just shows like this. While trying to use rosservice call/start it shows an error "This service is not available". Sols.pickle is also not found. Can you please help me resolve this issue, the college submission date is so close.

rencheckyoself commented 7 months ago

So all your problems are related to solverEOM never finishing. The start service doesn't exist because the node the offers if crashes (top-right pane). This is because the sols.pickle file isn't found because step 1 never finishes.

Step 1 does not require ROS so just run the python script by running: python3 SelfBalancing_AllSymbolic.py. Don't do anything past Step 1 until you are able to generate Sols.pickle and Ham.pickle. Again there might be issues because you are likely using newer versions for some of those dependencies have python3, sympy, numpy, scipy, and pickle.

AkhilAsok11 commented 7 months ago

Screenshot from 2024-04-06 18-04-37 Now when I try to run the solvereom it shows like this. I'm having a doubt about the hams.pickle file. While trying to run the other Python codes there was an error since the pickle extension was not installed in vs code. when I installed Pickle using vs code a hams.pickle was created automatically. Is this pickle file and the hams.pickle file that you mentioned are the same?

AkhilAsok11 commented 7 months ago

Now the SolverEOM is running. I will check it for 2 hours. Please do clarify the hams.pickle doubt.

AkhilAsok11 commented 7 months ago

Screenshot from 2024-04-06 21-19-51 Still after 2 hours, there is no change.

rencheckyoself commented 7 months ago

Yea, the SelfBalancing_AllSymbolic.py will generate two pickle files. Ham.pickle and Sols.pickle. These are the equations of motion that represent the self-balancing robot. Pickle is a package that should be bundled directly with Python.

I pulled the code to my machine and tried to run it and am getting the same behavior as you which leads me to think it's an issue with the newer versions of these packages not being compatible with my code. The program freezes when it gets to this line: https://github.com/rencheckyoself/self-balancing-robot/blob/a0bc76c4998d2fcb530cac204b792cd91f3da6be/SolveEOM/SelfBalancing_AllSymbolic.py#L286

My first guess at the issue is there's something up with the inputs to the sym.solve() function due to an update they've made since this was written 4 years ago. So you can dig into the Sympy documentation and debug what's causing the issue.

Something else that came to mind is making sure your computer isn't going to sleep/suspending/blanking the screen during that 2hr period. The one I tried it on did so that might also be the cause of it never finishing. I just started running it again and the program seems to be running because it's fully utilizing one of my CPU cores.

Another solution would be to install the version of Python 3 and the packages that would've existed in early 2020 and run it with them instead of whatever the current version is. Or even just make a bootable USB of Ubuntu 18 and try running it on that.

rencheckyoself commented 7 months ago

Also the program does seem to be generating a Ham.pickle file. It will get saved to the directory your terminal is set to when you run the SelfBalancing script. You can modify the print_solutions.py file to read and print the contents of Ham.pickle to verify the output is correct.

AkhilAsok11 commented 7 months ago

While running this solvereom my screen was always on even without blanking the screen. I will try to run the program using a bootable USB of Ubuntu 18. since I'm new to programming and ros I may not have the luxury of time to debug the sympy documentation. Is it possible to self-balance the robot without using the sovereom files? Can we use only pid files to self-balance the robot? Do you have the requirement file for this project?

rencheckyoself commented 7 months ago

I'm not sure what you mean by "requirement file". Step 1 computes the equations of motion for a self-balancing robot, but leaves everything in symbolic form. The pickle files are used to serialize those equations and save them for future use. Step 2 loads those pickle files and then uses those equations with an integrator to compute the motion of the drone. It's only in ROS as a tool for visualizing what the robot is doing. You can't just use the PID files alone because it needs the equations of motion from step 1.

I was digging through the repo and found that I saved the solutions at some point in a text file: https://github.com/rencheckyoself/self-balancing-robot/blob/master/documentation/solutions.txt Github doesn't allow pushing pickle files (or they didn't at the time) as a security precaution so I had to just do a text file.

You could use these to hard code the EOM in the ros node and eliminate the need for step 1. Here is where the Sols.pickle gets loaded: https://github.com/rencheckyoself/self-balancing-robot/blob/master/src/dynamics/nodes/simulate#L203C1-L223C84 Instead of using sympy to create the usable equations you could write 6 python functions that each take cur_loc as an input and returns the state value the fuction corresponds to. Something like:

def EOM_lxb(cur_loc):
     return <hardcoded function for xb>

Then you would need 5 more functions for the other 5 pieces of the state.

Then put those 6 functions into the self.eom_for_state variable instead of the the EOMl_* variables here: https://github.com/rencheckyoself/self-balancing-robot/blob/master/src/dynamics/nodes/simulate#L223

AkhilAsok11 commented 7 months ago

Tomorrow is my second last presentation of the project. Can I clarify some things about this project? Is the SelfBalancing_AllSymbolic.py file used to find the position and angle of the robot? EULER-LEGRANGE & HAMILTONIAN EQUATIONS are used in this to find the position and angle right? And after getting the angle and position it will be given to the PID controller to calculate the amount of torque that should to the controller. Is this the process that is happening through the Python files? Please do answer my queries. Now I'm trying to use cur_loc as you mentioned before. As I'm new to coding, I'm just thinking how to add this code properly "def EOM_lxb(cur_loc): return "

AkhilAsok11 commented 7 months ago

def EOM_lxb(cur_loc): return ( (0.5 rw) / (Iyyb Iyyw + 2.0 Iyyb mb * rw2 + 4.0 Iyyb mw * rw*2 + Iyyw hcom2 mb + 2.0 hcom2 * mb*2 rw2 * cos(cur_loc[10])2 + 4.0 * hcom*2 mb mw rw2) ) ( ( 4.0 hcom mb rw * (Iyyb + hcom2 mb) ( cur_loc[5]2 sin(cur_loc[4]) cos(cur_loc[10]) + 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[10]) cos(cur_loc[4]) + cur_loc[11]2 sin(cur_loc[4]) cos(cur_loc[10]) ) sin(cur_loc[4]) cos(cur_loc[4]) + 4.0 hcom mb rw (Iyyb + hcom2 mb) ( cur_loc[5]2 cos(cur_loc[4]) cos(cur_loc[10]) - 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[4]) sin(cur_loc[10]) + cur_loc[11]2 cos(cur_loc[4]) cos(cur_loc[10]) ) * cos(cur_loc[4])*2 - 4.0 hcom mb rw * (

def EOM_lyb(cur_loc): return (

def EOM_lpr(cur_loc): return (

def EOM_lpl(cur_loc): return (

def EOM_ltt(cur_loc): return (

self.eom_for_state = [EOM_lxb, EOM_lyb, EOM_ltb, EOM_lpr, EOM_lpl, EOM_ltt]

Is this the code which I need to use to replace the 6 functions code?

rencheckyoself commented 7 months ago

Yea, I think you have the correct understanding for what the package is doing and yes that looks like what I had in mind for the code change.

AkhilAsok11 commented 7 months ago

While searching on Google I saw the usage of IMU sensor plugins to determine the angle of the robot. Are we using this plugin in this project? The Euler-Lagrange equations are used to find the position and angle right. So why are we using Hamilton equations? Have we used the dynamic model of the robot in the SelfBalancing_AllSymbolic.py file. And if it's used what is the benefit or need for the dynamic model?

rencheckyoself commented 7 months ago

No it's not using that plugin. Yes, the EL equations are being used to compute the state of the robot. Since we are using an integrator to propagate the state, the Hamilton equations can be used to evaluate the quality of the simulation and help determine if there was an error in the dynamic model. In short, they are a debugging tool.

SelfBalancing_AllSymbolic.py solves for the dynamic model, then the ros node uses it with a PID controller to simulate the robot. Since the equations were solved symbolically you can easily substitute in different properties such as mass, inertias, wheel size, axel distance, starting position, etc. Then we can observe the required torques, motor speeds, and motor accelerations required to control the robot and select a motor that is capable of matching this performance for the build.

AkhilAsok11 commented 7 months ago

The dynamic model is solved through the SelfBalancing_AllSymbolic.py file to obtain the equations of position and angle right? My doubt is that are we creating the PID controller using the equations of position and angle that we obtained by solving the dynamic model. Once we have the angle and position errors, do we input it directly into the PID controller to balance the robot? Or, do we incorporate this error into the position and angle equations to calculate a value, which is then fed into the PID controller to determine the correct motor torque? How do we determine the error in position and angle of the robot without employing sensors or plugins?

rencheckyoself commented 7 months ago

The symbolic equations have a variable for an applied torque, the PID controller fills in these values. The error used for the PID loop is calculated by comparing our setpoint (stay at the origin and remain upright) with the robot state computed from the EOM. We don't need sensors or plugins because this is not a full physics simulation (ROS uses gazebo for full physics simulations), the EOM are controlling everything and ROS is just used to visualize the robot state.

On the real robot, I used sensors to get the robot state.

AkhilAsok11 commented 7 months ago

def EOM_lxb(cur_loc): return ( (0.5 rw) / (Iyyb Iyyw + 2.0 Iyyb mb * rw2 + 4.0 Iyyb mw * rw*2 + Iyyw hcom2 mb + 2.0 hcom2 * mb*2 rw2 * cos(cur_loc[10])2 + 4.0 * hcom*2 mb mw rw2) ) ( ( 4.0 hcom mb rw * (Iyyb + hcom2 mb) ( cur_loc[5]2 sin(cur_loc[4]) cos(cur_loc[10]) + 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[10]) cos(cur_loc[4]) + cur_loc[11]2 sin(cur_loc[4]) cos(cur_loc[10]) ) sin(cur_loc[4]) cos(cur_loc[4]) + 4.0 hcom mb rw (Iyyb + hcom2 mb) ( cur_loc[5]2 cos(cur_loc[4]) cos(cur_loc[10]) - 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[4]) sin(cur_loc[10]) + cur_loc[11]2 cos(cur_loc[4]) cos(cur_loc[10]) ) cos(cur_loc[4])2 - 4.0 hcom mb rw ( - Izzb cur_loc[5]2 sin(cur_loc[10]) + g hcom mb + hcom2 mb cur_loc[5]2 sin(cur_loc[10]) ) sin(cur_loc[10]) cos(cur_loc[4]) cos(cur_loc[10]) + 4.0 rw2 cur_loc[5] (pld + prd) ( Iyyb mb + 2.0 Iyyb mw + hcom2 mb2 cos(cur_loc[10])2 + 2.0 hcom2 mb mw ) sin(cur_loc[4]) cos(cur_loc[4])2 + 2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + Iyyw hcom2 mb - 2.0 hcom2 * mb2 * rw*2 sin(cur_loc[4])4 sin(cur_loc[10])2 - 2.0 hcom2 mb2 rw2 * sin(cur_loc[4])2 * sin(cur_loc[10])*2 cos(cur_loc[4])2 + 2.0 rw2 (Iyyb + hcom2 mb) (mb + 2.0 mw) sin(cur_loc[4])2 ) ) sin(cur_loc[4]) - (2.0 Fw - Izzw * cur_loc[5]*2 sin(2.0 pl)) (Iyyb + hcom2 mb) cos(cur_loc[4]) - (2.0 Fw - Izzw cur_loc[5]*2 sin(2.0 pr)) (Iyyb + hcom*2 mb) * cos(cur_loc[4]) )

def EOM_lyb(cur_loc): return ( - (0.5 rw) / (Iyyb Iyyw + 2.0 Iyyb mb * rw2 + 4.0 Iyyb mw * rw*2 + Iyyw hcom2 mb + 2.0 hcom2 * mb*2 rw2 * cos(cur_loc[10])2 + 4.0 * hcom*2 mb mw rw2) ) ( - 4.0 hcom mb rw * (Iyyb + hcom2 mb) ( cur_loc[5]2 sin(cur_loc[4]) cos(cur_loc[10]) + 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[10]) cos(cur_loc[4]) + cur_loc[11]2 sin(cur_loc[4]) cos(cur_loc[10]) ) sin(cur_loc[4])2 + 4.0 hcom mb rw (Iyyb + hcom2 mb) ( cur_loc[5]2 cos(cur_loc[4]) cos(cur_loc[10]) - 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[4]) sin(cur_loc[10]) + cur_loc[11]2 cos(cur_loc[4]) cos(cur_loc[10]) ) sin(cur_loc[4]) cos(cur_loc[4]) + 4.0 hcom mb rw ( - Izzb cur_loc[5]2 sin(cur_loc[10]) + g hcom mb + hcom2 mb cur_loc[5]2 sin(cur_loc[10]) ) sin(cur_loc[4]) sin(cur_loc[10]) cos(cur_loc[10]) + 4.0 rw2 cur_loc[5] (pld + prd) ( Iyyb mb + 2.0 Iyyb mw + hcom2 mb2 cos(cur_loc[10])2 + 2.0 hcom2 mb mw ) sin(cur_loc[4])2 cos(cur_loc[4]) + 2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + 2.0 Iyyb mb rw2 cos(cur_loc[4])2 + 4.0 Iyyb mw rw2 cos(cur_loc[4])2 + Iyyw hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 hcom2 mb mw rw2 ) sin(cur_loc[4]) cos(cur_loc[4]) ) def EOM_ltb(cur_loc): return ( (0.5 rw) / (Iyyb Iyyw + 2.0 Iyyb mb * rw2 + 4.0 Iyyb mw * rw*2 + Iyyw hcom2 mb + 2.0 hcom2 * mb*2 rw2 * cos(cur_loc[10])2 + 4.0 * hcom*2 mb mw rw2) ) ( - 2.0 hcom mb rw ( cur_loc[5]2 sin(cur_loc[4]) cos(cur_loc[10]) + 2.0 cur_loc[5] cur_loc[11] sin(cur_loc[10]) cos(cur_loc[4]) + cur_loc[11]2 sin(cur_loc[4]) cos(cur_loc[10]) ) sin(cur_loc[10]) + 2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + 2.0 Iyyb mb rw2 cos(cur_loc[4])2 + 4.0 Iyyb mw rw2 cos(cur_loc[4])2 + Iyyw hcom2 mb + 2.0 hcom2 mb2 * rw*2 cos(cur_loc[10])2 + 4.0 hcom2 mb mw rw2 ) * sin(cur_loc[10]) )

def EOM_lpr(cur_loc): return ( - (2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + 2.0 Iyyb mb * rw2 cos(cur_loc[4])2 + 4.0 Iyyb mw rw2 cos(cur_loc[4])2 + Iyyw hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 * hcom2 mb mw * rw2 )) / ( Iyyb Iyyw + 2.0 Iyyb mb rw2 + 4.0 Iyyb mw * rw2 + Iyyw * hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 hcom2 mb mw rw2 ) )

def EOM_lpl(cur_loc): return ( - (2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + 2.0 Iyyb mb * rw2 cos(cur_loc[4])2 + 4.0 Iyyb mw rw2 cos(cur_loc[4])2 + Iyyw hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 * hcom2 mb mw * rw2 )) / ( Iyyb Iyyw + 2.0 Iyyb mb rw2 + 4.0 Iyyb mw * rw2 + Iyyw * hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 hcom2 mb mw rw2 ) )

def EOM_ltt(cur_loc): return ( - (2.0 cur_loc[5] (pld + prd) ( Iyyb Iyyw + 2.0 Iyyb mb * rw2 cos(cur_loc[4])2 + 4.0 Iyyb mw rw2 cos(cur_loc[4])2 + Iyyw hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 * hcom2 mb mw * rw2 )) / ( Iyyb Iyyw + 2.0 Iyyb mb rw2 + 4.0 Iyyb mw * rw2 + Iyyw * hcom2 mb + 2.0 hcom2 * mb2 * rw*2 cos(cur_loc[10])2 + 4.0 hcom2 mb mw rw2 ) )

self.eom_for_state = [EOM_lxb, EOM_lyb, EOM_ltb, EOM_lpr, EOM_lpl, EOM_ltt]

Is this the code which I need to use to replace the 6 functions code?

While hardcoding this mb,rw, Iyyw, etc.. was not defined. i tried to define it but I can't understand what is F{w} in this code. Can you please define F{w}.

rencheckyoself commented 7 months ago

https://github.com/rencheckyoself/self-balancing-robot/blob/master/src/dynamics/nodes/simulate#L176C1-L199C115

You'll have to either change the class variables to match your hard coded equations or vice versa.

AkhilAsok11 commented 7 months ago

Ya, I changed all the variables in the hard code like m_b to mbody , h{com} to COMz, etc... but only for the variable F_{w} I don't know what to give.

rencheckyoself commented 7 months ago

https://github.com/rencheckyoself/self-balancing-robot/blob/master/src/dynamics/nodes/simulate#L248C1-L257C65

Its the output from the PID control for motor torque. You'll need to add a second variable the input for your hardcoded functions

AkhilAsok11 commented 7 months ago

Screenshot from 2024-04-11 18-09-21 Now after running the simulate file it shows this error, I made some changes to the code. But I haven't added a second variable. I don't know how can I define that variable. simulate.zip This is the current code of my simulate file.

AkhilAsok11 commented 7 months ago

Screenshot from 2024-04-12 14-52-25 how can I resolve the error? While running the simulate node the robot's chassis moves up and very fast and wheels will not move. when I run the rosservice call/start the simulate node will show this error and the movement of the chassis in the rvis will stop. While checking your YouTube video I saw that only the launch file rosservice call/start is used. But in my case rosservice call/start will not work until I run the simulate node. Can you please help me with this issue?