mbsim-env / mbsim

A multi-body simulation software
https://www.mbsim-env.de
GNU Lesser General Public License v2.1
42 stars 16 forks source link

Using mbsim for tricycle dynamics #47

Open dpeinado opened 2 years ago

dpeinado commented 2 years ago

Hello, perhaps this is not the correct place to adress this question. If there is another place, please let me know.

I'm starting using mbsim software. It's an awesome piece of software and so it's very complex. I've studying the examples under examples/xml and I've made some progress.

Now I have a tricycle model, but to analyse specific stability problems I can not manage to configure the software.

For example, I would like to run a case in which the tricycle goes straight, then makes a constant radius turn (180º), and returns straight. This should be done with an almost constant velocity, and the model shall be stable.

I've defined the trajectory as a planar contour, and tried to establish a bilateral contact between one point in the tricycle and the trajectory. It does not work. I should also define the rotation of the direction following the curve, but I do not know how to make it.

I've experimented with kinetic excitations, imposing a moment in the steering, but when turning, if I make the moment null, then it goes inestable (no handling force acting).

If I could impose a time rotation between both parts then I would control the steering, but I have not been able to do it.

I've seen some very complex models in which sensors, signals, and controllers are used so the moment applied to the steering depends on the dynamics of the model, but I would prefer to skip all this complexity if possible.

I will send you my model to see if you can help me.

In any case, thanks for maintaining this amazing software, regards

modelo1.zip .

foerg commented 2 years ago

Thanks for your positive feedback about MBSim. If you want to skip the complexity of a controlled system, i would suggest to use a "piecewise defined function" or a "piecewise polynom function" to define the steering angle. This would correspond to an ideal controller. However, as you have no feedback from the system, the proper function must be discovered by trail and error. An exemplary implementation is attached below. tricycle.zip

dpeinado commented 2 years ago

Thank you very much Martin. It works!!! And now I know something new about MBSim, the piecewise defined function (x coordinate is time, and y is the driven dimension). I would like to learn how to set up a controlled system, but I'll try from a simple system to more elaborated one. I can make tutorials, or make some documentation if you want. Thanks again!!

foerg commented 2 years ago

Nice if it works now. If you intend to set up a controller you can also have a look at https://github.com/mbsim-env/mbsim/tree/master/models/control. Here you can find a few templates for basic control elements, e.g. a PID controller. Feel free to contribute to the MBSim project, e.g. by a tutorial or by any documentation. That would definitely be useful.

dpeinado commented 2 years ago

Thank you very much Martin. I've prepared this example to make a basic tutorial for controlling with a PID. I have to write and probably explain the basics of the linear transfer system applied to a PID controller. But for making more appealing the tutorial, I would like to make a variable setting point. In this case as the error signal is directly the x coordinate, then the setting point is x=0. I also would like to have for example a time varying setting. Also I would like to compute the error signal from the trajectory I made in the tricycle example. Is it possible to compute the error with respect a trajectory? Thanks in advance.

Control_basics.zip

foerg commented 2 years ago

Hi Diego, I modified your example a little bit. The reference position named "ReferencePosition" is now given as symbolic function (I just used a sinus function here). The signal operation named "Error" computes the difference between the reference position and the measured position, which is the input for the PID controller. I also enabled the plot feature "signal" so that the signals can be displayed as a function of time within h5plotserie. The computation of the error with respect to the trajectory in your tricycle example should work the same way. Hope this helps. Control_basics.zip

dpeinado commented 2 years ago

Thanks Martin. I almost got there alone, but your example has been very useful. Now I'm trying to use controllers because there is no other way to do what I want to do. The controller related to the velocity (motor controller) is done. Now, I'm with the steering controller. I have to use two controllers. One that tracks the trajectory, and another to control the moment needed for mantain a steer angle. So the output of one controller feeds the other one. But I have a problem. To track angles, it is very useful to use the atan2 function. But always I use it, I receive an error: atan2: wrong type argument 'swig_ref' I've tracked this error to SWIG (Simplified Wrapper and Interface Generator), so it's used to connect the c++ code of mbsim to octave (aka matlab), but I don't know how to handle it. Do you know how to use atan2 using signals as inputs? Thanks in advance, best regards.

PS: If I succed in this example I would like to incorporate to the project, explaining how I did it.

foerg commented 2 years ago

Hi Diego, atan2(x,y) is not supported by symbolic function, but atan(x/y) should work.

dpeinado commented 2 years ago

Hi Martin. Yes, it should, but I have a problem when making big turns. The idea is of the simulation is as follows: There is a rigid body ("punto") which position is specified by time dependent translation with a piecewise defined funtion as you kindly suggested. It's position is measured with a position sensor called TrajectoryPosition. The Cart position is as well measured. Also a tangent vector is calculated for the Cart from velocity. An error is calculated as difference between position vectors of the trajectory and the cart. After that an error for motor, motor controller and kinetic excitation for rear wheel is computed. There is no problem on that. Now the motor is not conected (there is no axis for the moment). The steering control would be done with two controllers. First one that computes the difference between intendend trajectory and real one, and the output of this first controller should be the steering angle (delta). Then another controller has to be used so a moment is calculated to have the required delta. Here I have problems. To debug those problems, I'm testing only the delta controller. There is a TEST_DELTA_ANGLE that gives a reference for this angle. The question is how to measure this delta angle that is a relative angle between the cart and the bike. I have used Orientation Sensor for the cart and for the bike. I used one expression but the -pi, pi range of atan gave me problems as one big jump was produced. Now I use the method given in the bike example, but the problem still arises when a big turn is done by cart or bike. If you run the file given you'll see that everything goes smooth until 8.1 seconds in which the delta measured gives a big jump and the controller makes the cart turn down. Do you know a better way to measure the relative angle between cart and bike?? (the steering angle) Thank you for your help, best regards.

CorneringStability.zip

foerg commented 2 years ago

Hie Diego, you can measure the steering angle directly. The model is attached below. CorneringStability.zip By the way, I temporarily disabled all elements that are not needed. You can enable them again in the context menu of the element (right-click on the respective tree item). Best regards.

dpeinado commented 2 years ago

Thanks a lot!!! I've finally understood the difference between generalized position sensor and position sensor. The former has only the generalized coordinates left free by the constraints. As the bike only has one rotational dof, thats the sensor. Thanks again!!!