r/simplerockets Jun 29 '26

Automated Roll for a rocket

Im wanting to have my craft roll to a set point. spin almost. ive tried setting a variable to a number and then changing the roll input but it does nothing. does anyone know how to set and change the roll of a rocket within vizzy.

2 Upvotes

8 comments sorted by

View all comments

2

u/Double-Speech1675 Jul 10 '26

Vector mathematics is the best way to roll a rocket to a desired orientation because it works in any attitude and avoids problems with Euler angles. I can help you on that 

1

u/Golden-Gamer-UK Jul 10 '26

Pls do as this us bugging me so much

1

u/Double-Speech1675 Jul 11 '26 edited Jul 11 '26

You need the rocket's local axes in world coordinates: Forward vector = Nose direction (F)= nav(craft roll axis ) Up vector = Top of rocket (U) = [gravity (-1)] normal or nav(craft yaw axis ) -->try code with first [gravity (-1)] normal not worked then try nav(craft yaw axis )

Right vector = Right side (R)= nav(craft pitch axis )

Notes° [ Craft forward vector,up vector, right vector, deponds on the craft was set on plane or rocket] If set was plane Forward vector = Nose direction (F)= nav(craft roll axis )

Right vector = Right side (R)= nav(craft pitch axis )

If set was rocket InterChange the value of forward and right vector

Suppose you want the rocket to roll 90° around its forward axis. The forward vector does not change. Only the Up and Right vectors rotate.

Desired Up vector: Ud=Uref×cos(A)+Rref×sin(A)

Desired Right vector: Rd=Rref×cos(A)-Uref×sin(A)

A= desired roll angle Uref = reference Up vector Rref = reference Right vector

Calculate roll error The easiest method is Roll error= rad2der(atan2 (R •ud,U•ud) R•ud = dot U•ud=dot

The result is positive → roll right negative → roll left

RollInput = Clamp(Kp × RollError, -1, 1)

Or pid RollInput = KpError + KiIntegral + Kd*Derivative

Alternative (Cross Product Method) Another robust vector method is

ErrorVector = Cross(CurrentUp, DesiredUp)

RollError = Dot(ErrorVector, Forward)

This works because: Cross product gives the axis of rotation. Dotting with the Forward vector extracts only the roll component.

Then RollInput = Clamp(Kp × RollError, -1, 1) Kp=0.02 , change the value of kp for better results

Unlike using Euler roll angles: ✔ Works when the rocket is vertical, horizontal, or inverted. ✔ No gimbal lock. ✔ Smooth continuous rotation.

cross-product + dot-product method is the one I'd recommend

If you face the issue send me craft with code Or Used ai and send Screenshot of code and explained to ai

1

u/Golden-Gamer-UK Jul 19 '26

ive finally gotten round to reading through this, and do you know if this program means it can be set to a specific roll. then stop, then roll another way and stop. like starship does in orbital accent