Mercurial > tote
changeset 154:8c4bb05fd129 teensy31
Use float instead of double
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 28 Jun 2015 23:35:42 +0200 |
| parents | 78335bffa4b8 |
| children | 7f7811e22e63 |
| files | start/creep.h start/creep.ino start/leg.h start/leg.ino start/servos.h start/servos.ino |
| diffstat | 6 files changed, 46 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/start/creep.h Sun Jun 28 23:02:02 2015 +0200 +++ b/start/creep.h Sun Jun 28 23:35:42 2015 +0200 @@ -2,11 +2,11 @@ #define CREEP_H /* Walking speed. */ -extern double creep_dx; // Sideways. -extern double creep_dy; // Forward. -extern double creep_spread; -extern double creep_rotation; -extern double creep_height; +extern float creep_dx; // Sideways. +extern float creep_dy; // Forward. +extern float creep_spread; +extern float creep_rotation; +extern float creep_height; /* Perform one step of the creep gait with the current speed. */ void walk();
--- a/start/creep.ino Sun Jun 28 23:02:02 2015 +0200 +++ b/start/creep.ino Sun Jun 28 23:35:42 2015 +0200 @@ -28,15 +28,15 @@ }; /* Body position. */ -static double _shift_x = 0.0; -static double _shift_y = 0.0; +static float _shift_x = 0.0; +static float _shift_y = 0.0; /* Walking speed. */ -double creep_dx = 0.0; // Sideways. -double creep_dy = 1.0; // Forward. -double creep_rotation = 0.0; // Rotation. -double creep_height = TIBIA; // Body height. -double creep_spread = 0.0; // Leg spread. +float creep_dx = 0.0; // Sideways. +float creep_dy = 1.0; // Forward. +float creep_rotation = 0.0; // Rotation. +float creep_height = TIBIA; // Body height. +float creep_spread = 0.0; // Leg spread. /* Which legs are touching the ground? */ static bool _on_ground[4] = {true, true, true, true}; @@ -67,7 +67,7 @@ } /* Shifts the whole body by defined amount. */ -void _shift_body_by(double dx, double dy) { +void _shift_body_by(float dx, float dy) { for (unsigned char leg=0; leg < 4; ++leg) { move_leg_by(leg, dx * LEG_X[leg], dy * LEG_Y[leg], 0); } @@ -77,8 +77,8 @@ /* Shifts the body away from the given leg, for balance. */ void _shift_body(unsigned char leg) { - double dx = (LEG_X[leg] * SHIFT - _shift_x) / SHIFT_STEPS; - double dy = (LEG_Y[leg] * SHIFT - _shift_y) / SHIFT_STEPS; + float dx = (LEG_X[leg] * SHIFT - _shift_x) / SHIFT_STEPS; + float dy = (LEG_Y[leg] * SHIFT - _shift_y) / SHIFT_STEPS; for (unsigned char i = 0; i < SHIFT_STEPS; ++i) { _shift_body_by(dx, dy); _creep_tick(); @@ -177,7 +177,7 @@ /* Perform one step of a walk, selected depending on the speed. */ void walk() { static unsigned char leg = 0; - double max_speed = max(abs(creep_rotation), + float max_speed = max(abs(creep_rotation), max(abs(creep_dx), abs(creep_dy))); if (max_speed > 1.5) {
--- a/start/leg.h Sun Jun 28 23:02:02 2015 +0200 +++ b/start/leg.h Sun Jun 28 23:35:42 2015 +0200 @@ -1,18 +1,18 @@ #ifndef LEG_H #define LEG_H -const double COXA = 12.0; -const double FEMUR = 42.0; -const double TIBIA = 38.5; -const double BASE = 21.0; +const float COXA = 12.0; +const float FEMUR = 42.0; +const float TIBIA = 38.5; +const float BASE = 21.0; const char LEG_X[4] = {-1, -1, 1, 1}; const char LEG_Y[4] = {1, -1, -1, 1}; -extern double leg_position[4][3]; -const double HOME = (COXA + FEMUR) / SQRT2; +extern float leg_position[4][3]; +const float HOME = (COXA + FEMUR) / SQRT2; -bool move_leg(unsigned char leg, double x, double y, double z); -bool move_leg_by(unsigned char leg, double dx, double dy, double dz); -bool rotate_leg_by(unsigned char leg, double angle); +bool move_leg(unsigned char leg, float x, float y, float z); +bool move_leg_by(unsigned char leg, float dx, float dy, float dz); +bool rotate_leg_by(unsigned char leg, float angle); #endif
--- a/start/leg.ino Sun Jun 28 23:02:02 2015 +0200 +++ b/start/leg.ino Sun Jun 28 23:35:42 2015 +0200 @@ -8,7 +8,7 @@ {9, 10, 11}, }; -double leg_position[4][3] = { +float leg_position[4][3] = { {HOME, LEG_Y[0] * HOME, -TIBIA}, {HOME, LEG_Y[0] * HOME, -TIBIA}, {HOME, LEG_Y[0] * HOME, -TIBIA}, @@ -16,7 +16,7 @@ }; -double _solve_triangle(double a, double b, double c) { +float _solve_triangle(float a, float b, float c) { // Calculate the angle between a and b, opposite to c. a = abs(a); b = abs(b); @@ -25,17 +25,17 @@ return acos((a * a + b * b - c * c) / (2 * a * b)); } -double _norm(double a, double b) { +float _norm(float a, float b) { // Calculate the norm of a vector. return sqrt(a * a + b * b); } -bool _inverse_kinematics(double x, double y, double z, - double *ankle, double *knee, double *hip) { +bool _inverse_kinematics(float x, float y, float z, + float *ankle, float *knee, float *hip) { // Calculate angles for knee and ankle, and put them in those variables. // Return true on success, and false if x and y are out of range. - double f = _norm(x, y) - COXA; - double d = _norm(f, z); + float f = _norm(x, y) - COXA; + float d = _norm(f, z); // if (d > FEMUR + TIBIA) { return false; } d = min(d, FEMUR + TIBIA); *hip = atan2(y, x); @@ -47,11 +47,11 @@ return true; } -bool move_leg(unsigned char leg, double x, double y, double z) { +bool move_leg(unsigned char leg, float x, float y, float z) { // Move the tip of the leg to x, y. Return false when out of range. - double ankle = NaN; - double knee = NaN; - double hip = NaN; + float ankle = NaN; + float knee = NaN; + float hip = NaN; leg_position[leg][0] = x; leg_position[leg][1] = y; leg_position[leg][2] = z; @@ -65,7 +65,7 @@ return true; } -bool move_leg_by(unsigned char leg, double dx, double dy, double dz) { +bool move_leg_by(unsigned char leg, float dx, float dy, float dz) { // Move the tip of the leg by dx, dy. Return false when out of range. return move_leg(leg, leg_position[leg][0] + dx, @@ -73,11 +73,11 @@ leg_position[leg][2] + dz); } -bool rotate_leg_by(unsigned char leg, double angle) { +bool rotate_leg_by(unsigned char leg, float angle) { // Rotate the tip of the leg around the center of robot's body. - double x = leg_position[leg][0] + BASE; - double y = leg_position[leg][1] + BASE; - double nx = x * cos(angle) - y * sin(angle) - BASE; - double ny = x * sin(angle) + y * cos(angle) - BASE; + float x = leg_position[leg][0] + BASE; + float y = leg_position[leg][1] + BASE; + float nx = x * cos(angle) - y * sin(angle) - BASE; + float ny = x * sin(angle) + y * cos(angle) - BASE; return move_leg(leg, nx, ny, leg_position[leg][2]); }
--- a/start/servos.h Sun Jun 28 23:02:02 2015 +0200 +++ b/start/servos.h Sun Jun 28 23:35:42 2015 +0200 @@ -4,7 +4,7 @@ // Number of servos. #define SERVOS 12 -void servo_move(unsigned char servo, double rads); +void servo_move(unsigned char servo, float rads); void servo_setup(void); void servo_shutdown(void);
--- a/start/servos.ino Sun Jun 28 23:02:02 2015 +0200 +++ b/start/servos.ino Sun Jun 28 23:35:42 2015 +0200 @@ -34,7 +34,7 @@ }; static Servo servos[SERVOS]; -static const double HOME_POSITION[SERVOS] = { +static const float HOME_POSITION[SERVOS] = { // ankle, knee, hip 0, 0, 0, // front left 0, 0, 0, // hind left @@ -42,7 +42,7 @@ 0, 0, 0 // front right }; -static const double FOLD_POSITION[SERVOS] = { +static const float FOLD_POSITION[SERVOS] = { // ankle, knee, hip -PI2, PI2, -PI4, // front left -PI2, PI2, -PI4, // hind left @@ -50,7 +50,7 @@ -PI2, PI2, -PI4 // front right }; -void servo_move(unsigned char servo, double rads) { +void servo_move(unsigned char servo, float rads) { // Move a servo to a position in radians between -PI/2 and PI/2. long int freq;
