Bayley Wang
/
dc_motor_control
bad dc motor controller with current mode
Diff: CommandProcessor/cmd_mode.cpp
- Revision:
- 0:2b1edabdd26b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CommandProcessor/cmd_mode.cpp Sun Feb 03 03:38:05 2019 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +#include "CommandProcessor.h" + +#include "globals.h" + +void cmd_setp(Serial *pc, char *buf) { + float dtc = atof(buf); + if (dtc < 0.0f) dtc = 0.0f; + if (dtc > 1.0f) dtc = 1.0f; + user_cmd = dtc; +} + +void cmd_freq(Serial *pc, char *buf) { + float freq = atof(buf); + if (freq < 500.0f) freq = 500.0f; + if (freq > 10000.0f) freq = 10000.0f; + TIM1->ARR = (int) ((float) 9e7 / freq); +} + +void cmd_src(Serial *pc, char *buf) { + int n = str_to_src(buf); + if (n < 0) { + pc->printf("%s\n", "Invalid Source"); + return; + } + BREMS_src = n; + pc->printf("Set source to %s\n", src_to_str(n)); +} + +void cmd_op(Serial *pc, char *buf) { + int n = str_to_op(buf); + if (n < 0) { + pc->printf("%s\n", "Invalid operation"); + return; + } + BREMS_op = n; + pc->printf("Set operation to %s\n", op_to_str(n)); +} + \ No newline at end of file