Skip to content

Instantly share code, notes, and snippets.

@mabdrabo
Last active December 29, 2020 08:21
Show Gist options
  • Save mabdrabo/6757174 to your computer and use it in GitHub Desktop.
Save mabdrabo/6757174 to your computer and use it in GitHub Desktop.
given a few basic info about the robot or vehicle, gives an approximate to what is really needed.
<!DOCTYPE html>
<html>
<head>
<title>DC motor calculator</title>
<script>
function calculate () {
mass = document.getElementById('mass').value;
acceleration = document.getElementById('acceleration').value;
speed = document.getElementById('speed').value;
radius = document.getElementById('radius').value;
circumference = eval(radius * 2 * 3.14);
force = eval(mass * acceleration);
torque = eval(force * radius);
rps = eval(speed / circumference);
rpm = eval(rps * 60);
power_wt = eval(torque * rpm * 0.1047);
power_hp = eval(torque * rpm * 0.1047);
document.getElementById('force').innerHTML = force;
document.getElementById('torque').innerHTML = torque;
document.getElementById('rps').innerHTML = rps;
document.getElementById('rpm').innerHTML = rpm;
document.getElementById('power_wt').innerHTML = power_wt;
document.getElementById('power_hp').innerHTML = power_hp;
alert(power_hp);
}
</script>
</head>
<body>
<label>Mass (Kg): </label>
<input type="text" id="mass" placeholder="Mass">
<label>Acceleration (m/s^2): </label>
<input type="text" id="acceleration" placeholder="Acceleration">
<br/>
<label>Speed (m/s): </label>
<input type="text" id="speed" placeholder="Speed">
<label>Wheel Radius (m): </label>
<input type="text" id="radius" placeholder="Wheel Radius">
<br/>
<input type="button" value="Calculate" onClick="calculate();">
<hr/>
<hr/>
Force (N): <label id="force"></label>
<br/>
Torque (N.m): <label id="torque"></label>
<br/>
RPS: <label id="rps"></label>
<br/>
RPM: <label id="rpm"></label>
<br/>
Power (watt): <label id="power_wt"></label>
<br/>
Power (hp): <label id="power_hp"></label>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment