Skip to content

Bug/rcs available torque#552

Merged
djungelorm merged 5 commits intokrpc:masterfrom
FumbieNumbie:bug/rcs-available-torque
Oct 2, 2019
Merged

Bug/rcs available torque#552
djungelorm merged 5 commits intokrpc:masterfrom
FumbieNumbie:bug/rcs-available-torque

Conversation

@FumbieNumbie
Copy link
Contributor

No description provided.

@djungelorm djungelorm added this to the 0.4.9 milestone Oct 2, 2019
@djungelorm djungelorm added bug Something isn't working service:space-center labels Oct 2, 2019
@djungelorm
Copy link
Member

I've merged these changes into the branch bug/rcs-torque. Travis should have a build ready soon for you to try.

I made two fixes to your code: the y and z axes were swapped in the output (should be x = pitch, y = yaw, z = roll)
Also, turns out the negative torque values need to be negative values to match how torque works for reaction control wheels, wings etc.

Could you try out the latest build on Travis to confirm this works correctly? I've done some reasonably thorough testing and it all seems to check out, but good to get someone else to check!

@djungelorm
Copy link
Member

Travis built dev version with these changes is here: https://krpc.s3.amazonaws.com/deploy/bug/rcs-torque/1370/krpc-0.4.9-132-g5b87d7f.zip

@FumbieNumbie
Copy link
Contributor Author

It works. And you are right, the axes were switched. And without negative values I wonder how it worked for me. Oh, well.

@djungelorm
Copy link
Member

Cool! I'll merge it to master then. Thanks

@djungelorm
Copy link
Member

djungelorm commented Oct 2, 2019

I was doing some more testing and was getting strange results when the thruster was placed such that it produced torque around more than one axis (for example when I tested with a single RCS thruster it was somehow able to produce both positive and negative torque around the same axis which is impossible).

Looks like the original code splits up the components of the cross product (as torque = pos x force), but that isn't quite right - not sure why you did it that way? I get better results with the following:

// Torque around X (pitch) - this is the x component of the pos force cross product
torque = posY * forceZ - posZ * forceY;
if (torque > 0) torqueX += torque;
else torqueXn += -torque;
// Torque around Y (yaw) - this is the y component of the pos force cross product
torque = posZ * forceX - posX * forceZ;
if (torque > 0) torqueY += torque;
else torqueYn += -torque;
// Torque around Z (roll) - this is the z component of the pos force cross product
torque = posX * forceY - posY * forceX;
if (torque > 0) torqueZ += torque;
else torqueZn += -torque;

@djungelorm
Copy link
Member

djungelorm commented Oct 2, 2019

Related to #354

@djungelorm djungelorm merged commit 3c0c74e into krpc:master Oct 2, 2019
@FumbieNumbie
Copy link
Contributor Author

Looks like the original code splits up the components of the cross product (as torque = pos x force), but that isn't quite right - not sure why you did it that way?

I think if I calculated the cross product I'd have to deal with calculating an angle between two vectors. And then I would still have to take a product's components individually since just summarising cross poducts for every thruster would result in a vector with a magnitude 0. Otherwise I would have to find a way to distribute vectors by their contribution to positive or negative torque.
I think my approach is neater. If I made a mistake, please explain. I like linear algebra and I'd like to know more.

@djungelorm
Copy link
Member

djungelorm commented Oct 3, 2019

You don't need to compute angles or do any trigonometry to compute a cross product.

The part I don't think was right was just the torque calculation inside the loop. I agree that we want to compute the torque vector of each thruster separately, and extract the component around the pitch, yaw, roll axes and add them to the overall positive and negative torques as appropriate.

To explain the code I have merged into master:

  • Torque produced by an individual thruster is defined as the cross product of the position vector of the thruster (from the center of mass of the vessel) and the force vector (in the vessels reference frame).
  • A cross product can be computed element wise as follows:
    (ax,ay,az) x (bx,by,bz) = (ay*bz - az*by, ax*bz - az*bx, ax*by - ay*bx)
  • So using the above equation to compute torques we have:
    torque around x axis (pitch) = posy*forcez - posz*forcey
    torque around y axis (yaw) = posx*forcez - posz*forcex
    torque around z axis (roll) = posx*forcey - posy*forcex
  • Each of these is tested whether it is positive or negative, and then accumulated into the overall positive and negative torques around the pitch, yaw, roll axes (as you had in the original code).

The difference is that your code computes the following torque contributions:

  • torque around x axis (pitch) = posy*forcez
  • torque around x axis (pitch) = posz*forcey
  • torque around y axis (yaw) = posx*forcez
  • torque around y axis (yaw) = posz*forcex`
  • torque around z axis (roll) = posx*forcey
  • torque around z axis (roll) = posy*forcex

Looks like you separated the cross product equations into two parts (e.g. splitting up posy*forcez - posz*forcey into posy*forcez and posz*forcey and considering these as separate contributions to positive and negative torque.

Also, your code doesn't really make intuitive sense. If you had a single thruster, the code can produce torque values where the thruster can produce a torque around in both a positive and negative direction around a single axis. But a single thruster can only induce a torque in one direction around a given axis.

@djungelorm
Copy link
Member

Maybe best to chat on discord if this doesn't make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working service:space-center

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants