Please select Into the mobile phone version | Continue to access the computer ver.
Non Linear Movment Part Deux - Drift Turns
1004 2 2019-8-7
Uploading and Loding Picture ...(0/1)
o(^-^)o
MarkusXL
lvl.4
United States
Offline

By adding a cosine function to input number streams into the Direction of Translation argument "Theta Zero" of our mecanum function, truly non-linear movement is acheived.

Even at painfully slow speeds, the S1 now appears to "drift" and "slide" through turns.  I'm tickled pink.  This is a trip to behold.

Adjust all the variables at the top to play with this expanded and cleaned up code snippet.

TODO:  Add yet another math function to tweak the Max Wheel RPM argument Vd during the loop.  Now we're talking crazy, as the value of Vd can be negative, to go backwards.  Maybe the S1 can move like a Spriograph thingy...


from time import sleep
from math import sin, cos, radians, pi, fabs

Vd = 25                # Init and set Max Wheel RPM (approximately)
Vo = 0                 # Init Translation Heading Vo
T0 = 0                 # Init Translation Angle Theta Zero
Tm = 0.2               # Init Time Delay between loops
sign_changer1 = -1.0   # Tick tock for Heading Angle Vo
sign_changer2 = -1.0   # Tick tock for Lateral sliding T0
start1 = 30            # Start heading count (try 0 and see for yourself)
stop1 = 230            # Stop heading count (the bigger the merrier)
trfact = 0.3           # Turn Radius Factor
ltfact = 10            # Lateral Translation Factor


def mecanum(Vd, Vo, T0):

    V0 = Vd * (sin(radians(T0) + pi / 4) + Vo)
    V1 = Vd * (cos(radians(T0) + pi / 4) - Vo)
    V2 = Vd * (cos(radians(T0) + pi / 4) + Vo)
    V3 = Vd * (sin(radians(T0) + pi / 4) - Vo)
    return V0, V1, V2, V3


for n in range(start1, stop1):
    Vo = (trfact * (1 + sin(radians(n * 10)))) * sign_changer1
    T0 = (ltfact * (1 + cos(radians(n * 10)))) * sign_changer2
    if fabs(Vo) < .01:
        sign_changer1 = sign_changer1 * -1.0
        print(sign_changer1)
    if fabs(T0) > 45:
        sign_changer2 = sign_changer2 * -1.0
        print(sign_changer2)
    print(Vo, T0)
    V = mecanum(Vd, Vo, T0)
    chassis_ctrl.set_wheel_speed(V[0], V[1], V[2], V[3])
    print(V[0], V[1], V[2], V[3])
    sleep(Tm)


2019-8-7
Use props
MarkusXL
lvl.4
United States
Offline

# This re-write of the mecanum function may seem redundant, but it was
# needed to get a feel for how Turn Factor Vo interacts with the
# Direction of Translation Theta Zero
# The settings specified here will make a fast, cannon-in circle
# about a half meter radius.

from
math import sin, cos, radians, pi
from time import sleep

Vd = 60       # Init Speed in RPM (100 is pretty fast)
Vo = 0.7      # Init Turn Factor (-3.0 to + 3.0)
T0 = 90       # Init Theta Zero (direction of Translation in degrees)
Tm = 5        # Time of movement in seconds


def mecanum(Vd, Vo, T0):

    V0 = Vd * (sin(radians(T0) + pi / 4) + Vo)
    V1 = Vd * (cos(radians(T0) + pi / 4) - Vo)
    V2 = Vd * (cos(radians(T0) + pi / 4) + Vo)
    V3 = Vd * (sin(radians(T0) + pi / 4) - Vo)
    return V0, V1, V2, V3


print(Vd, Vo, T0)
V = mecanum(Vd, Vo, T0)
chassis_ctrl.set_wheel_speed(V[0], V[1], V[2], V[3])
print(V[0], V[1], V[2], V[3])
sleep(Tm)
2019-8-8
Use props
DJI Stephen
DJI team
Offline

Hello and good day MarkusXL. Thank you for sharing this information and this program that you have created. Thank you for your valued support.
2019-8-9
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules