View unanswered posts | View active topics It is currently Thu Oct 30, 2014 11:15 am






Reply to topic  [ 6 posts ] 
Question about setMotorTarget 
Author Message
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 22
Location: Margraten, The Netherlands
Post Question about setMotorTarget
The setMotorTarget command tells the robot to move an absolute distance. Now look at my sample code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,20);  //Target: 90, Speed: 20

As expected the motor turns 90 degrees clockwise.
Now look at this code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,-20);  //Target: 90, Speed: -20

Here I would expect the motor to turn 270 degrees counterclockwise to the absolute position of 90 degrees, but instead it turns 90 degrees counterclockwise. To my oppinion that's not logical or am I wrong?


Fri Sep 26, 2014 10:26 am
Profile
Rookie

Joined: Tue Dec 11, 2012 9:19 pm
Posts: 47
Post Re: Question about setMotorTarget
KeesSmit wrote:
The setMotorTarget command tells the robot to move an absolute distance. Now look at my sample code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,20);  //Target: 90, Speed: 20

As expected the motor turns 90 degrees clockwise.
Now look at this code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,-20);  //Target: 90, Speed: -20

Here I would expect the motor to turn 270 degrees counterclockwise to the absolute position of 90 degrees, but instead it turns 90 degrees counterclockwise. To my oppinion that's not logical or am I wrong?


I don't use lego motors often, but I'd expect it to do exactly
what you observed it do. This is consistent with the behavior
of motors in other contexts. If you tell a motor to move at a
negative speed, it moves in the reverse direction.

Here's it has moved in the reverse direction exactly as far as you
told it to. Seems pretty clear.


Fri Sep 26, 2014 12:14 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 157
Post Re: Question about setMotorTarget
KeesSmit wrote:
The setMotorTarget command tells the robot to move an absolute distance. Now look at my sample code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,20);  //Target: 90, Speed: 20

As expected the motor turns 90 degrees clockwise.
Now look at this code:
Code:
resetMotorEncoder(motorC);
setMotorTarget(motorC,90,-20);  //Target: 90, Speed: -20

Here I would expect the motor to turn 270 degrees counterclockwise to the absolute position of 90 degrees, but instead it turns 90 degrees counterclockwise. To my oppinion that's not logical or am I wrong?


Looking at the documentation, I do not believe that absolute position means that every degree is assigned a number 0-359. It means that you can tell it to go to any position from the lowest number the firmware can record for an encoder to the highest number. You also have to give it a power value in the correct direction to get it there.

For instance, the encoder value can be at 1000, and you tell it to go to -2000 at a power of -75. It will turn a total of 3000 degrees counter clockwise. Now, it seems like you've discovered a part of it that's not mentioned in the documentation. From the behavior you described, it seems like if you give it a power value that will take it in the opposite direction of the target, it will flip the sign of the target value.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Fri Sep 26, 2014 1:11 pm
Profile
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 22
Location: Margraten, The Netherlands
Post Re: Question about setMotorTarget
I made a new test program:
Code:
#pragma config(Motor,  motorC,          MedMotor,       tmotorEV3_Medium, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   resetMotorEncoder(motorC);
   displayTextLine(1,"T1:%3d - E1:%3d",getMotorTarget(motorC),getMotorEncoder(motorC));
   
   // Step 1
   setMotorTarget(motorC,90,20);
   waitUntilMotorStop(motorC);
   displayTextLine(3,"T2:%3d - E2:%3d",getMotorTarget(motorC),getMotorEncoder(motorC));
   sleep(1000);

   // Step 2
   setMotorTarget(motorC,90,20);
   waitUntilMotorStop(motorC);
   displayTextLine(5,"T3:%3d - E3:%3d",getMotorTarget(motorC),getMotorEncoder(motorC));
   sleep(1000);

   // Step 3
   setMotorTarget(motorC,90,20);
   waitUntilMotorStop(motorC);
   displayTextLine(7,"T4:%3d - E4:%3d",getMotorTarget(motorC),getMotorEncoder(motorC));
   sleep(4000);
}


When you run this program the motor turns 90 degrees clockwise in Step 1. In Step 2 and 3 it's standing (almost) still as expected.
When changing speed in all three setMotorTarget commands to -20 the following occurs:
- Step 1: motor turns 90 degrees counterclockwise.
- Step 2: motor turns 180 degrees counterclockwise.
- Step 3: motor turns 360 degrees counter clockwise.
:?:


Fri Sep 26, 2014 1:45 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 157
Post Re: Question about setMotorTarget
KeesSmit wrote:
When you run this program the motor turns 90 degrees clockwise in Step 1. In Step 2 and 3 it's standing (almost) still as expected.
When changing speed in all three setMotorTarget commands to -20 the following occurs:
- Step 1: motor turns 90 degrees counterclockwise.
- Step 2: motor turns 180 degrees counterclockwise.
- Step 3: motor turns 360 degrees counter clockwise.
:?:


That is bizarre behavior. :eek:

My best guess is that internally it subtracts the current position from the target to get the distance to move. Then it moves in the direction specified by the power by the absolute value of the distance it calculates. So with the positive power that would produce:

1. 90 - 0 = 90 degrees (moves to +90)
2. 90 - 90 = 0 degrees (moves to +90)
3. 90 - 90 = 0 degrees (moves to +90)

with a negative power, this would produce:

1. 90 - 0 = 90 degrees (moves to -90)
2. 90 - (-90) = 180 degrees (moves to -270)
3. 90 - (-270) = 360 degrees (moves to -630)

Best advice: if you want it to go clockwise, make sure your target is larger than your current position and your power is positive. If you want it to go counterclockwise, make sure your target is smaller than your current position and your power is negative.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Fri Sep 26, 2014 4:11 pm
Profile
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 22
Location: Margraten, The Netherlands
Post Re: Question about setMotorTarget
Seems like a possible explanation. I was just testing this to figure out the difference between moveMotorTarget en setMotorTarget when I ran up to this issue. Thanks for your help!


Fri Sep 26, 2014 4:23 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.