control torques in joints

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

control torques in joints

Postby blackbird_dream » Thu Mar 25, 2021 12:24 pm

Hi Julio.
Is it possible to input torque values in dCustomHinge joints ?
Or the only way is using dCustomHingeActuator ?
Thks
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: control torques in joints

Postby Julio Jerez » Thu Mar 25, 2021 1:01 pm

The actuator does not work with torque either.
It work with a desired acceleration of the control axis.

You can just read the joint axis and apply a torque pair to each body.
One to one body and the negation of the one to the other body. This will be if you are trying to make a motor.

For some external torque that is applied to a body you can just add the torque to that body.
It works either way.

A simple way would be, subclass the hinge joint and the you can set the torque in the callback before calling the base call. This could be wrong if you are considering gyro forces because the external torque are part of the calculation, and if yo add the torque for one joint the labor that body is counted to some other body, the torque will be different.

A more correct way is to make listener, and in the preupdate, apply all the extra torque to all the bodies and all the joint control at once to that array of bodies and joints.
The the joint will have all the data it needs.

Essentially you are asking for a new object I am calling a model in newton 4, but that in 3.xx is a listener.

A model is a collection of bodies, joints and shapes that get thier update at the proper time.
An example is a vehicle where torque and some other controll ha to be known ahead of the solver.
Joint and force callback are not the best for this because there is no way they can be organized to be can in the correct order the application need it, but the listener can do that.
Another example is what you are doing.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: control torques in joints

Postby blackbird_dream » Fri Mar 26, 2021 2:21 am

Thks Julio. That's clear.
For the moment we stay with Newton3 as there is much implemented until now.
We are currently using a listener (provided by Koom) and up to now we input the torque directly on the parent bodies, action and reaction, as you wrote. So, It can work this way as you suggest.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: control torques in joints

Postby MeltingPlastic » Fri Nov 26, 2021 6:23 pm

Hi Julio,

What if there are 2 bodies, and we want a specified torque between them?

For example 2 cylinders with with a dCustomHinge between them. If the 2 cylinders have equal mass then the 2 cylinders would start rotating in opposite directions with the same (and increasing) speed.

I added a 3rd option in dCustomHinge, using NewtonUserJointSetRowAcceleration:

Code: Select all
if (m_options.m_option2 || m_options.m_option3) {
      // the joint is motor
      dFloat accel;
      if (m_options.m_option3)
      {
                       
         dFloat mass;
         dFloat dummy;

         NewtonBodyGetMass(m_body0, &mass, &dummy, &dummy, &dummy);
         if (m_body1) {
            dFloat mass2;
            NewtonBodyGetMass(m_body1, &mass2, &dummy, &dummy, &dummy);
            mass += mass2;
         }

         accel = m_motorTorque/mass;
      }
      else
      {
         accel = (m_motorSpeed - m_jointOmega) / timestep;
      }
      
      NewtonUserJointAddAngularRow(m_joint, 0.0f, &matrix0.m_front[0]);
      NewtonUserJointSetRowAcceleration(m_joint, accel);
      NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
      NewtonUserJointSetRowMinimumFriction(m_joint, -m_friction);
      NewtonUserJointSetRowMaximumFriction(m_joint, m_friction);
   } else {


And this seems to work, but I'm not sure if I'm handling mass correctly? So If I add a torque of 1. That it would actually be 1 Nm between the 2 bodies?

I'm still on 3.xx

Thanks
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: control torques in joints

Postby Julio Jerez » Sat Nov 27, 2021 11:59 am

Oh, that's a huge mistake, that fir some reason I do not understand people keeps making over a over.
But do not feel bad, I see even the self appointed experst making and not only that trying to normalize it.

Basically what you want is a motor.
The parameters that define a motor are
Rpm and torque, therefor those are the parameter you need to use.


To control a motor, in the callback you can do something like.

1- calculate the relative angular velocity of the two axis.

2-calculater the difference between the relative velocity and the desired motor rmp.

3- divide that difference by the time step. This will give the acceleration needed but the joint, so yo set that as the joint acceleration.

4- set the min and max torque limits, as the positive and negative value of the desire torque.

And that's all you need to do.

You have a motor that can model any real life motor.

You can control the torque, and also the ram at will.
Adding a torque, is not just a mistake, it is also wrong.

Just think about, a torque imply a constant acceleration which mean and ever increasing rmp, but you has never seen a motor acting like that.

But with the method I explained above, you just say
Set the target ramp, and the max torque.

Not the motor will acceleration fast or slowly, depend on how strong the torque is. But it will accelerate until it reach the target rpm.

But it does not stops there, it will also handle the load appropriately. Basically the answers to that last question that if it will handle the mass.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: control torques in joints

Postby Julio Jerez » Sat Nov 27, 2021 12:11 pm

By using that method, rmp and max torque.
You will find that you could simulate many real like cases.

For example, you head all the time the car can do 0, to 60 in 3.1 second,

Basically, you take the motor pick torque, and peak rmp.
And you sau, my desire acceleration is the peak rpm, and the max true is the engine torque
You apply that and measure the speed at 3.1 second.

And as long as it above or below that value that give to a metric to adjust the gear, or tire ratio and so on.

Other cases for example a elevator.
I move at a contant speed regardless the load.

So the parameter are again max speed, and the variable is the true limit.

Has you try 4.00? Yet.

If not please try, I have try to make these thing more eassy
My goal is to make the first stable release by the year end.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: control torques in joints

Postby MeltingPlastic » Sat Nov 27, 2021 12:56 pm

So lets say I want to control torque dynamically with the current stock hinge code:

PseudoCode:
Code: Select all
void CommandTorque(float commandedTorque)
{
float commandedTorque= 10; // 10Nm
dCustomHingeActuator->SetAngularRate(infinity*Sign(desiredTorque))
dCustomHingeActuator->SetMaxTorque(desiredTorque)
}


I think this makes sense. What causes me initial confusion is there is no dCustomHingeMotor->SetTorque() or similar.

I guess a c++ class could be made that implements it the same way dCustomHingeActuator does.

I have implemented Field Oriented Control on a motor using a microcontroller. And from a hardware control standpoint Torque is actually the main input (in the form of current limiting). All the control laws are built by taking the current angle and angular velocity, etc and then commanding a torque. Alot of robot motors are have different "Modes", Torque Control, Angular Velocity Control, Position Control, etc.




I have been following 4.0 and testing the sandbox. I plan on updating My Urho3D Bindings soon if I can. Exciting to see the solver updates.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: control torques in joints

Postby Julio Jerez » Sat Nov 27, 2021 4:34 pm

you can subclass from, hinge in the same way that dCustomHingeActuator.h does.
dCustomHingeActuator.h is what would be more or less equivalent of a normal step motor, bu no exacply, because the joint is not discrete. Tha could be arranged by quantizing the angle, but I do not think that's what you want.

I have implemented Field Oriented Control on a motor using a microcontroller. And from a hardware control standpoint Torque is actually the main input (in the form of current limiting). All the control laws are built by taking the current angle and angular velocity, etc and then commanding a torque. Alot of robot motors are have different "Modes", Torque Control, Angular Velocity Control, Position Control, etc.


I think you want a normal induction or async motro, this already a functionality of the dCustomHinge
these functions are you interface to control it

Code: Select all
   CUSTOM_JOINTS_API dFloat GetFriction () const;   
   CUSTOM_JOINTS_API void SetFriction (dFloat frictionTorque);

   CUSTOM_JOINTS_API dFloat GetJointOmega () const;
   CUSTOM_JOINTS_API void EnableMotor(bool state, dFloat motorSpeed);
friction act as the torque or as the resistance.
and induction motor, the speed is determined by the frequency of by the load.

is you want to make it a vcd motor, meaning a motor in which the speed is a function or the torque,

the you can make a linear function that make the desire speed and function of the friction toque.
that way you control the rpm with only with the torque.

on this
I have been following 4.0 and testing the sandbox. I plan on updating My Urho3D Bindings soon if I can. Exciting to see the solver updates.

I am experimenting with a new variant of the solver, that does not build island.
it turned out to be quite a hard challenge.
one of the reasons for that is that build island of connected bodies make it possible to apply many post update heuristics, so that is can get away with fewer solve iteration.

the problem is building island algorithms are purely sequential, and parallelizing them requires atomic operation and the end result is that at best they offer some marginal speed with a low number of cores. but as you start increasing cpu or GPU cores, they ready a limit where all core get block at the place with the atomic operation are.

I have success make the entre solver atomic free, with the exception of that part.
but that has been quite difficult.
I will continue for few days, because I am still convinced it is possible, but if in few days I am not successful, I will simply leave as it is and just make the one for High core count be island free.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests