11 years, 1 month ago.

It's should be Left or Right?

Hello, when I use m3pi source code, I find these code that have made me dizzy.

void m3pi::left_motor (float speed) { motor(0,speed); }

void m3pi::right_motor (float speed) { motor(1,speed); }

0: left wheel 1: right wheel

but in the following code, 1 is M1(leftwheel), 0 is M2(rightwheel), WHY??? void m3pi::motor (int motor, float speed) { char opcode = 0x0; if (speed > 0.0) { if (motor==1) opcode = M1_FORWARD; else opcode = M2_FORWARD; } else { if (motor==1) opcode = M1_BACKWARD; else opcode = M2_BACKWARD; } unsigned char arg = 0x7f * abs(speed);

_ser.putc(opcode); _ser.putc(arg); }

THANK YOU!

Code tags helps the viewer understand the code you wrote:

This is encoded with code tags

void m3pi::left_motor (float speed) { 
     motor(0,speed); 
}

void m3pi::right_motor (float speed) { 
     motor(1,speed);
} 

void m3pi::motor (int motor, float speed) { 
     char opcode = 0x0; 
     if (speed > 0.0) { 
          if (motor==1) opcode = M1_FORWARD; 
     else opcode = M2_FORWARD; 
     } else { 
          if (motor==1) opcode = M1_BACKWARD; 
          else opcode = M2_BACKWARD; 
     } 
     unsigned char arg = 0x7f * abs(speed);
     _ser.putc(opcode); _ser.putc(arg); 
}
posted by Christian Lerche 30 Apr 2013
Be the first to answer this question.