Skip to content

Commit cbcbfe4

Browse files
committed
fix motor as well
1 parent 4558b6f commit cbcbfe4

File tree

1 file changed

+18
-28
lines changed

1 file changed

+18
-28
lines changed

src/Motor.cpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,37 +87,27 @@ void Motor::Update(float linear_speed_mms, float linear_direction_rad, float ang
8787

8888
void Motor::HandleCommand(Command cmd)
8989
{
90-
// maybe this should be handled in a generic commands handler and dispatcher
91-
if (!cmd.cmd.startsWith("Motor")){
92-
println("Not a Motor Command ");
93-
return;
94-
}
95-
96-
// why do we check "Motor" twice?
97-
if (cmd.cmd != "Motor" || cmd.size != 3)
90+
if (cmd.cmd == "Motor" && cmd.size == 3)
9891
{
99-
println("Invalid Motor Command");
100-
return;
101-
}
92+
// Motor:1;1000;50
93+
// Motor:1;1;50
94+
if (cmd.data[2] < 0 || 100 < cmd.data[2])
95+
{
96+
println("Invalid Duty Cycle");
97+
return;
98+
}
10299

103-
// Motor:1;1000;50
104-
// Motor:1;1;50
105-
if (cmd.data[2] < 0 || 100 < cmd.data[2])
106-
{
107-
println("Invalid Duty Cycle");
108-
return;
100+
print("Motor ", cmd.data[0]);
101+
print(" with freq ", cmd.data[1], " Hz");
102+
println(" with duty ", cmd.data[2], " %");
103+
104+
if (cmd.data[0] == 1)
105+
stepper1->setPWM(cmd.data[1], cmd.data[2]);
106+
if (cmd.data[0] == 2)
107+
stepper2->setPWM(cmd.data[1], cmd.data[2]);
108+
if (cmd.data[0] == 3 && motorBaseType == OMNIDIRECTIONAL_3_MOTORS)
109+
stepper3->setPWM(cmd.data[1], cmd.data[2]);
109110
}
110-
111-
print("Motor ", cmd.data[0]);
112-
print(" with freq ", cmd.data[1], " Hz");
113-
println(" with duty ", cmd.data[2], " %");
114-
115-
if (cmd.data[0] == 1)
116-
stepper1->setPWM(cmd.data[1], cmd.data[2]);
117-
if (cmd.data[0] == 2)
118-
stepper2->setPWM(cmd.data[1], cmd.data[2]);
119-
if (cmd.data[0] == 3 && motorBaseType == OMNIDIRECTIONAL_3_MOTORS)
120-
stepper3->setPWM(cmd.data[1], cmd.data[2]);
121111
}
122112

123113
void Motor::PrintCommandHelp()

0 commit comments

Comments
 (0)