View unanswered posts | View active topics It is currently Sun Sep 20, 2020 10:11 pm

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
Rookie

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
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
Novice

Joined: Tue Dec 11, 2012 9:19 pm
Posts: 58
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
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
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://bluechariotsoffire.com/.

Fri Sep 26, 2014 1:11 pm
Rookie

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
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
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
 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.

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://bluechariotsoffire.com/.

Fri Sep 26, 2014 4:11 pm
Rookie

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning