Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CAN/CAN_com.cpp
- Revision:
- 59:8fb0145aa933
- Parent:
- 58:312f8ec71d74
diff -r 312f8ec71d74 -r 8fb0145aa933 CAN/CAN_com.cpp
--- a/CAN/CAN_com.cpp Tue Dec 01 06:29:10 2020 +0000
+++ b/CAN/CAN_com.cpp Fri Jan 22 12:44:34 2021 +0000
@@ -1,15 +1,10 @@
#include "CAN_com.h"
- #define P_MIN -12.5f
#define P_MAX 12.5f
- #define V_MIN -65.0f
- #define V_MAX 65.0f
- #define KP_MIN 0.0f
- #define KP_MAX 500.0f
- #define KD_MIN 0.0f
- #define KD_MAX 5.0f
- #define T_MIN -3.0f
+ #define V_MAX 270.0f
+ #define KP_MAX 50.0f
+ #define KD_MAX 0.5f
#define T_MAX 3.0f
@@ -25,9 +20,11 @@
/// 3: [velocity[3-0], current[11-8]]
/// 4: [current[7-0]]
void pack_reply(CANMessage *msg, float p, float v, float t){
- int p_int = float_to_uint(p, P_MIN, P_MAX, 16);
- int v_int = float_to_uint(v, V_MIN, V_MAX, 12);
- int t_int = float_to_uint(t, -T_MAX, T_MAX, 12);
+
+ int p_int = float_to_uint_symmetric<16>(p, P_MAX);
+ int v_int = float_to_uint_symmetric<12>(v, V_MAX);
+ int t_int = float_to_uint_symmetric<12>(t, T_MAX);
+
msg->data[0] = CAN_ID;
msg->data[1] = p_int>>8;
msg->data[2] = p_int&0xFF;
@@ -59,11 +56,11 @@
int kd_int = (msg.data[5]<<4)|(msg.data[6]>>4);
int t_int = ((msg.data[6]&0xF)<<8)|msg.data[7];
- controller->p_des = uint_to_float(p_int, P_MIN, P_MAX, 16);
- controller->v_des = uint_to_float(v_int, V_MIN, V_MAX, 12);
- controller->kp = uint_to_float(kp_int, KP_MIN, KP_MAX, 12);
- controller->kd = uint_to_float(kd_int, KD_MIN, KD_MAX, 12);
- controller->t_ff = uint_to_float(t_int, T_MIN, T_MAX, 12);
+ controller->p_des = uint_to_float_symmetric<16>(p_int, P_MAX);
+ controller->v_des = uint_to_float_symmetric<12>(v_int, V_MAX);
+ controller->kp = uint_to_float_positive<12>(kp_int, KP_MAX);
+ controller->kd = uint_to_float_positive<12>(kd_int, KD_MAX);
+ controller->t_ff = uint_to_float_symmetric<12>(t_int, T_MAX);
//printf("Received ");
//printf("%.3f %.3f %.3f %.3f %.3f %.3f", controller->p_des, controller->v_des, controller->kp, controller->kd, controller->t_ff, controller->i_q_ref);
//printf("\n\r");