Source

multi_func_test / dynamics.cpp

#include "WProgram.h"
#include "SPI.h"
#include "dynamics.h"

#define DFLT_MASS    1.0
#define DFLT_DT      1.0
#define DFLT_VEL     0.0
#define DFLT_POS     0.0
#define DFLT_DAMPING 0.0

Dynamics::Dynamics() {
    mass = DFLT_MASS;
    dt = DFLT_DT;
    vel = DFLT_VEL;
    pos = DFLT_POS;
    damping = DFLT_DAMPING;
}

void Dynamics::update(float force) {
    pos = pos + dt*vel;
    vel = vel + (dt/mass)*(force - damping*vel);
}

void Dynamics::setMass(float value) {
    mass = fabs(value);
}

void Dynamics::setDt(float value) {
    dt = fabs(value);
}

void Dynamics::setVelocity(float value) {
    vel = value;
}

void Dynamics::setPosition(float value) {
    pos = value;
}

void Dynamics::setDamping(float value) {
    damping = value;
}

float Dynamics::getPosition() {
    return pos;
}

float Dynamics::getVelocity() {
    return vel;
}

float Dynamics::getMass() {
    return mass;
}

float Dynamics::getDt() {
    return dt;
}

float Dynamics::getDamping() {
    return damping;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.