started building a simulation.
the problem is it goes straight but not is the right direction
if you need to know
awk '
function line (x0, y0, x1, y1, col) {
printf "color=%s\nnext\n", col
printf " %8.4f %8.4f\n", x0, y0
printf " %8.4f %8.4f\n", x1, y1
}
# --------------------------------------
function mark (x0, y0, dx, dy, col) {
line(x0 - dx, y0, x0 + dx, y0, col)
line(x0, y0 - dy, x0, y0 + dy, col)
}
# ----------------------------------------------------------
function disp (n) {
if (! (n % 10)) {
printf "#"
printf " %6s", "sec"
printf " %6s", "vL"
printf " %6s", "vR"
printf " %6s", "rL"
printf " %6s", "r"
printf " %6s", "v"
printf " %6s", "d"
printf " %6s", "dA"
printf " %6s", "ang"
printf " %6s", "x"
printf " %6s", "y"
printf "\n"
}
printf "#"
printf " %6.1f", sec
printf " %6.2f", vL
printf " %6.2f", vR
printf " %6.2f", rL
printf " %6.2f", r
printf " %6.2f", v
printf " %6.2f", d
printf " %6.2f", dA
printf " %6.2f", ang
printf " %6.2f", x0
printf " %6.2f", y0
printf " %6.1f", x1
printf " %6.1f", y1
printf " %6.2f", eL
printf " %6.2f", eR
printf "\n"
}
# ------------------------------------------------
function abs (x) {
if (0 > x)
return -x
return x
}
# ------------------------------------------------
function adv (n) {
sec += dTsec
# if (0.1 < abs(vL - vR)) {
if (1) {
rL = D * vL / (vR - vL)
r = rL + D / 2
v = (vR + vL) / 2
d = v * dTsec
dA = -180 * d / (Pi * r)
}
else
dA = 0
w0 = (ang ) * Pi / 180 # compass
x1 = x0 - r * cos(w0)
y1 = y0 + r * sin(w0)
ang += dA
w1 = (ang ) * Pi / 180 # compass
x2 = x1 + r * cos(w1)
y2 = y1 - r * sin(w1)
dx = 1
dy = 1
# mark(x1, y1, dx, dy, n+2)
# mark(x2, y2, dx, dy, n+2)
line(x0, y0, x2, y2, "cyan")
disp(n)
x0 = x2
y0 = y2
if (vL > vR) {
# printf "# - rotating right\n"
# exit
}
}
# ------------------------------------------------
function pid (err) {
Kp = 0.08
Kp = 0
Ki = 0.4
Kd = 0
acc += Ki * err
errLst = err
return err * Kp + acc
}
# ------------------------------------------------
BEGIN {
Pi = atan2(0, -1)
E = 20 # tic/rev
K = 0.9
Dia = 2 # in.
D = 6 # in. between wheels
ang = 0
x0 = y0 = 0
vR = 1 # rev /sec
vL = K * vR
printf "thickness = 1.8\n"
dx = 0.1
line(-dx, 0, dx, 0, "dark-gray")
line( 0, -1, 0, 30, "dark-gray")
dTsec = 0.1
for (n = 0; n < 300; n++) {
eL += E * dTsec * vL
eR += E * dTsec * vR
vL = pid(eR - eL)
adv(n)
}
}' | tee 2wd.xgr