Skip to content

Instantly share code, notes, and snippets.

@collinalexbell
Last active September 11, 2017 16:28
Show Gist options
  • Save collinalexbell/6e894addf58ff3acbd28dbd8d0caeaf6 to your computer and use it in GitHub Desktop.
Save collinalexbell/6e894addf58ff3acbd28dbd8d0caeaf6 to your computer and use it in GitHub Desktop.
(ns torque-sim.core)
;;I want to calculate the strenght of motors needed for a robot of various parameters
(defn get-motor-strength
[robot-femur-length robot-torso-weight]
()
)
(def g 9.8)
(defn torque
([a m l] (* a m l))
([f l] (* f l)))
(defn gravitational-torque
[mass length]
(torque g mass length))
(defn moment-of-inertia
[t m values]
(case t
:point (let [distance-of-point-from-axis (first values)]
(* m (java.lang.Math/pow
distance-of-point-from-axis 2)))))
(defn acceleration-from-d-and-t
[d t]
(/ (* 2 d) (java.lang.Math/pow t 2)))
(defn max-rpm [a t]
(* 60 (/ (* a t) (* 2 3.14))))
(defn nm->kg-cm [nm]
(* 100 (/ nm 9.8)))
(defn torque-required
([mass ;;kg
radial-acceleration ;;rads/sec^2
length ;;meters
]
(*
(/ 1 9.8)
(* 100)
(+ (gravitational-torque mass length)
(torque (moment-of-inertia :point mass [length])
radial-acceleration)))
;;rv returned in kg-cm
)
([mass
time
radians
length-of-arm
& {:keys [motor-max-rpm]
:or {motor-max-rpm 600}}
]
(let [a
(acceleration-from-d-and-t (/ radians 2)
(/ time 2))
max-rpm
(max-rpm a time)
torque-required
(torque-required mass a length-of-arm)
gearing-ratio (/ motor-max-rpm max-rpm)]
{:torque-required torque-required
:max-rpm max-rpm
:gearing-ratio gearing-ratio
:motor-torque-required (/ torque-required gearing-ratio)})))
;;22 kg robot to take 1 second to stand (90 degree feumur movement) with a femur length of .2m . Also, stepper motors effecient rpm maxes at around 500.
(torque-required 22 1 (/ 3.14 2) 0.2 :motor-max-rpm 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment