p4labs / p4-robotsim

2D Arduino robot simulation powering Dawson Engineering Physics Virtual Lab
MIT License
6 stars 1 forks source link

Help on Math for 3D Version #4

Open ricardojlrufino opened 2 years ago

ricardojlrufino commented 2 years ago

Hello, I'm creating a 3d version for simulation. I'm having some problems with the math part...

I got a success taking the formulas of the example: https://ricardojlrufino@github.com/artica/DifferentialDriveSimulator-Processing/blob/master/robot.pde

But there are still a series of fixed values that I don't understand what they are for... and not how to model to get a simulation closer to the real thing. For example, the example does not consider the size of the wheels nor the size of the chassis.

Equation locations: https://github.com/ricardojlrufino/TwoWheel-Robot_3D_Simulation/blob/master/src/3d/RobotCar3d.ts#L118

image

This is my example using BabylongJS https://github.com/ricardojlrufino/TwoWheel-Robot_3D_Simulation

image

tawjaw commented 2 years ago

hi @ricardojlrufino I think these constants you are seeing are just optimized by trial and error to get to a speed you like.

For example I have https://github.com/p4labs/p4-robotsim/blob/90d181769a2005918933494fbe3a618206ef359e/src/robots/TwoWheelRobot.ts#L33

which I just multiply by the force I am applying at the wheels.

So I think it is something like that. especially the *17.

I've actually built a 3D version of the simulation before. It is not open source. It was a proof of concept kind of. And I am planning on building a proper one.

You can play with it here. It's an archive of a site we had couple of years ago. https://mcgill-hackathon-kb7e6.ondigitalocean.app/challenge/sandbox.html

The problem that I see in your approach is that you are not simulating the robot in 3D (I think), you are just transforming the position of the robot and the direction, and updating the rendering.

But if the ground is not flat surface then it doesn't matter to your simulation. The size of the wheel doesn't matter. The mass of the robot doesn't matter etc.

What I did in that simulation is using a 3D physics library ammojs And the robot was being simulated as a 3D object. The wheels are also separate 3D objects and there are joint constraints defined for them.

And the wheels are literally rotating. And the friction with the ground is causing the movement of the robot.

ricardojlrufino commented 2 years ago

The problem that I see in your approach is that you are not simulating the robot in 3D (I think), you are just transforming the position of the robot and the direction, and updating the rendering.

As I want to implement a line follower, the parameters I'm basing on are the (left, right wheel velocity). I honestly don't know if that's enough.

I'm not from the academic field either, my field of study is more IoT...

I'm just playing around with AVR8js and I found your project... So I wanted to implement it in 3d.

The problem is that with this bunch of fixed values: 100, 17, dt = 1/30... as you said it seems like a lot of trial and error...

ricardojlrufino commented 2 years ago

image I noticed that when I press STOP, the rear lifts up a little... interesting

tawjaw commented 2 years ago

As I want to implement a line follower, the parameters I'm basing on are the (left, right wheel velocity). I honestly don't know if that's enough.

With this only, you are basically doing something similar to the 2D simulation but in a 3D render. Meaning you're not considering the Z axis in the simulation. And that could be enough if that's what you want.

In the 2D simulation, the force applied to the robot is not affected by the ground, it is assuming a flat surface all the time.

So if you are okay with these boundaries, then your approach should be fine.

You wouldn't be able to have a non flat surface. And if you extend it to adding obstacles and ultrasonic sensor, then you'd be doing a lot of physics calculations yourself for collision detection to make it happen.

Which is why I went with a physics engine before. The simulation you are looking into seems like it is using a simple 2D differential equation to find the position and angle of the robot with respect to time.

The problem is that with this bunch of fixed values: 100, 17, dt = 1/30... as you said it seems like a lot of trial and error...

This differential equation is assuming the robot's mass and the force that the motor is applying. But the code doesn't specify those variables.. it just looks like they are used as constants. Which makes it difficult to understand and modify the parameters.

I think this might help you understand how to derive such differential equation

https://youtu.be/9Gk5DDtsoOE

ricardojlrufino commented 2 years ago

I believe I found out that the 17, is probably the L variable (distance between the wheels) Changing the value, the robot's movement, makes a circle bigger or smaller.. image from : https://youtu.be/XG4cODYVbJk?t=230

ricardojlrufino commented 2 years ago

With this only, you are basically doing something similar to the 2D simulation but in a 3D render

For now yes. I'm not looking to mess with physics at the moment.

So if you are okay with these boundaries, then your approach should be fine.

Thanks for the explanations.

ricardojlrufino commented 2 years ago

Added speed control. I could see that the rotation is not correct, if I change the speed L to the maximum. I believe it remains to find the rotation pivot. image

I converted sample into babylonjs playground https://playground.babylonjs.com/#5LD51R#33