Inverting motor's rotation

I've designed a robot with two motors. It works as follows:

The first motor is attached to the the person's arm, the second motor receives the calculated movement and moves accordingly.

When the person moves his hand (open/close) the other robot moves the the opposite direction; upon opening it closes and vise-versa.

I've tried to invert the movement by multiplying by -1 but the second motor keeps moving on his own. I've tried multiplying the results of both motors, before subtracting, with no success.

The 'code' does the following:

1. I take the movements of motors A and B
2. Subtract value of motor A from motor B's
3. Save the result to a variable-'moveDist'
4. Take the absolute value after subtraction for comparison
5. If greater than 6, pass 'moveDist' value to the second motor.

• Sorry, don't know how to post my code, here's a link: i.imgur.com/OR2uAMP.png Also I have a video demonstrating what happens to the hand after the multiplication(If you wanna see). – bio512 May 13 '15 at 17:22
• I'm not at all well-versed in the spaghetticode that comes from LEGO's EV3 software, but conceptually, isn't the "take the absolute value" part unnecessary and even wrong? Shouldn't you be moving B the difference between A and B so that B' = B+ (A-B) = A ? – Phil B. May 13 '15 at 18:29
• That's why I used the variable 'moveDist', to save the B' value. The absolute value is used for comparison (A threshold), if I don't do so, the hand will keep on shaking. – bio512 May 14 '15 at 10:23
• Ok I see that now - couple of more things: You need to clarify what the issue is: is it that movements seem to be mirrored but passing -1 * MoveDist does not seem to reverse the movement? or is it that but the second motor keeps moving on his own. - i.e. motor B keeps making movements even if motor A does not register any movement (or movements below your '6' threshold)? – Phil B. May 14 '15 at 11:27

I think the main problem is, that you use the "Motor on for # degrees". The program will wait until this command is executed (i.e. the required turn is made), and this can take quite long. The next measurement of the angle difference is taken after that. Having a high start deviation and/or fast turning rates of your reference motor, you will not get a stable result. Instead I propose to use the angle difference for the "Power" input of the "Motor on" command. In that scenario the angle difference is measured very often, and the "slave" motor is following your "master" motor very pecisely.

• Thanks for the reply, appreciate it. Won't be able to test it until next Wednesday, only then I can give my feedback. One thing, the 'slave' motor, in my project, is desired to move in 180 degrees, does the 'On' mode treat that aspect? – bio512 May 17 '15 at 16:28
• I want it to move by the given degree and then stop. The ev3 help says: "The motor will run until it is stopped or changed by another block". – bio512 May 17 '15 at 20:22
• Since the angle difference is the "power" input of the slave motor, it will only move untill the difference is zero. So it will follow exactly your "master" motor. If that master stays within 180°, the slave will, too. And don't worry about the timing, one loop cycle in above program takes only ~1ms. So the deviation is checked and corrected ~1000 times per sec. – alexs May 18 '15 at 13:01
• I tested the code and unfortunately it didn't help. – bio512 May 21 '15 at 19:56

I found a solution: I multiplied the master motor's value by -1. So, the calculation was: (a-b) it changed to : (-a-b). The result was passed to the slave motor and it did the job.

• If you want the blocks, feel free to ask. – bio512 May 21 '15 at 20:00