View unanswered posts | View active topics It is currently Thu Aug 28, 2014 10:01 pm






Reply to topic  [ 12 posts ] 
NXT Motor Speed 
Author Message
Rookie

Joined: Mon Oct 01, 2007 11:56 am
Posts: 7
Location: England
Post NXT Motor Speed
Hi there!

I'm new to the forum, and to RobotC! All my programming last year was done in NQC (I do RoboCup Junior Soccer Tournaments in the UK). Last year, our school's rescue team (of which I was also part of) used RobotC, but unfortunately, due to other commitments, I was unable to play any major part in the programming, and so did not understand what RobotC was about. This year however, I am playing a much more involved part in our school's soccer team, and we are obviously using RobotC.

I have been reviewing the forum for the past few days, and only just registered due to an error in the register page which has now been fixed, but nothing on the forum seems to do what I want to do. I feel that introducing people slowly into a new language is the best way of doing it, and the complexity of some of the code in some posts is way beyond me. I need to start simple, and the included "help" doesn't really suffice.

This is something I would very much like to do with the new NXT kit: use the nMotorPIDSpeedCtrl function. But the help and sample programs are not too easy to decipher, and I figured a simple explanation/tutorial would be useful. So, for example, if I wanted the robot to go in an exactly straight line to hit a ball (which is not an easy task), how would I go about this? :?

Thanks in advance,

Oliver Q


Mon Oct 01, 2007 1:10 pm
Profile WWW
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 439
Location: Pittsburgh, PA
Post 
Hi Oliver,

In order to use nMotorPIDSpeedCtrl, you must first enable it on the motor you wish to use, and then set the motor speed. The motor speed must be under 100.

Here is an example:

Code:
task main(){

   nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg;
   nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg;

   motor[motorC] = 50;
   motor[motorB] = 50;
   wait1Msec(5000);

   motor[motorC] = 0;
   motor[motorB] = 0;

}


That will have the robot run forward using motors C (left motor) and B (right motor) for 5 seconds while enabling PID speed control. Change your motor's accordingly to match your robot.

Please let me know if you have any other questions. Also, what problems did you run into with the forums other than the registration?

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Mon Oct 01, 2007 5:16 pm
Profile
Rookie

Joined: Mon Oct 01, 2007 11:56 am
Posts: 7
Location: England
Post 
Thanks for that! It was nothing technical. Just nothing matched (simply) what I wanted to do. :D


Tue Oct 02, 2007 1:27 pm
Profile WWW
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:44 am
Posts: 439
Location: Pittsburgh, PA
Post 
It's no problem at all. Please post if you have any other issues :)

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy | CS2N


Tue Oct 02, 2007 4:04 pm
Profile
Rookie
User avatar

Joined: Fri May 30, 2008 2:08 pm
Posts: 5
Post 
Hi,

I'm pretty new to RobotC as well and would like to know what's the difference between the code that you posted and this one:

Code:
task main()
{
  nSyncedMotors            = synchBC;
  nSyncedTurnRatio         = 100;
  nPidUpdateInterval       = 10;

  motor[motorB] =  50;
  wait1Msec(5000);

  motor[motorB] = 0;

}


It seems to me that both are going to do the same thing (go straight for 5 seconds). But are there any advantages of using one method instead of the other?

Thanks!


Fri May 30, 2008 2:14 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 
Indeed, I would love to know what the pros and cons are of both these methods. Why pick one over the other and more importantly, when?

Regards,
Xander


Sat May 31, 2008 10:55 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Hey everyone,

synchBC purpose is to make two motors mirror each other and enables you to command both motors by only commanding one motor. This can be usefully in many different applications, like driving and turning where the motors act together for the application. The nSyncedTurnRatio controls how the slave motor mirrors the master motor. This command can only be used when using the NXT servo motors (big white motor) because it uses the encoders (rotation sensors) built into them.

MotorPIDSpeedCtr changes how the motors are powered. Normally when you write motor[motorC] = 50, you are telling the NXT to run the motor to run half power, and it will maintain that power output. If MotorPIDSpeedCtr is enabled, motor[motorC] = 50 means run the NXT motor at half speed. If the motor encounters a stall and slows down, the NXT will provide more power to the motor to maintain the speed. This can be very useful for drive motors or motors that encounter allot of work or have a tenancy to stall without the speed control on. Disadvantages are that MotorPIDSpeedCtr only works with the NXT servo motor (big white motor) and it cannot supply more power than what the NXT motor consumes at full speed. One other observation is that MotorPIDSpeedCtr is not enabled when using motor encoder target command.

Hope these descriptions help, and feel free to ask any questions B-)
Scott

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Mon Jun 02, 2008 12:10 am
Profile WWW
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post 
starwarslegokid wrote:
One other observation is that MotorPIDSpeedCtr is not enabled when using motor encoder target command.


It was new to me (I might have not read the documentation thoroughly) and also quite important. 10x.


Mon Jun 02, 2008 1:06 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Iv noticed this with some experimentation, just though I would pass it along. I will mention it to Dick again and see whats going on.

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Mon Jun 02, 2008 1:10 am
Profile WWW
Rookie

Joined: Sun Jul 06, 2008 7:01 am
Posts: 1
Location: Portugal
Post Re: NXT Motor Speed
Hi everyone,
I was using motor encoder target command to control the motors of my robot. I noticed that the movement of the motor was dependent of the batteries charge. As the turning angle must be precise I've tried to use the MotorPIDSpeedCtr command to try to avoid this unstable behviour. I'm seeing now that the two commands can be not compatible. Do you have more information on this subject? Should I change the code to control if the motor encoder was reached instead of targeting a given motor encoder directly?


Sun Sep 07, 2008 11:57 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: NXT Motor Speed
jmpessanha wrote:
Hi everyone,
I was using motor encoder target command to control the motors of my robot. I noticed that the movement of the motor was dependent of the batteries charge. As the turning angle must be precise I've tried to use the MotorPIDSpeedCtr command to try to avoid this unstable behviour. I'm seeing now that the two commands can be not compatible. Do you have more information on this subject? Should I change the code to control if the motor encoder was reached instead of targeting a given motor encoder directly?

A couple of points.

When using PID control of a motor, it will not work if you're tryng to set a speed beyond the capabilities of the robot. As might occur if the batteries are weak, or you're going uphill, or the terrain is rough, or there is lots of friction in the drive train. Suppose a PID speed of 100 is nominally 1000 encoder counts per second. Suppose, considering the battery level the fastest motorA can currently perform is 750 counts per second and that motorB can run flat out at only 700 counts per second.

Now, if your program sets speed of motor A and B to 80 (which is 800 counts per second) they cannot achieve this speed. So the PID algorithm will apply continuous power to each motor and they will achieve 750 and 700 counts per second. This will not result in a straight line.

For the PID algorithm to have an effect, you need to set speed below the maximum so that the PID algorithm has a "chance" to make adjustments. A speed of 70 would not work because there is no margin for motor A. But if you set both motors to speed 60 you'd find that they both ran at 600 counts per second. And if you looked at the "NXT Devices" window in the debugger you'd see that the actual power level applied to each motor was closer to 90 or 95 with motor B being slightly higher than motor A.

The "Sync" motor command is intended to correct for the above problem by keeping both motors running at a constant ratio of speeds regardless of whether you're trying to run them beyond their current maximum speed limits. Return to the above configuration and suppose you've used "sync-ed" motor to travel in a straight line at speed 80.
  • The motors canactually travel only 750 or 700 encoder counts.
  • PID algorithm would rapidly get both motors to a maximum power level of 100.
  • Then a "sync" overlay is calculated. The target speed ratio is 1:1 for a straight line. But 750:700 is observed. So motor B is too slow and an adjustment is calculated. Let's suppose the adjustment calculation results in 20.
  • Adjustment calculation is applied to the two motors. Half to each. Motor A power is reduced to 90. Motor B power is increased to 110 but this is then coerced back to 100 which is the maximum value.
  • At the next update interval, the calculation is again redone. Let's suppose motor A travelled 725 counts this time (its powerwas reduced to 90) and motor B travelled 700.
  • The sync adjustment might result in a number like 14 (instead of 20). Motor A will be given 90 - 7 = 83 as power level. Motor B will continue at 100 + 7 = 107 which is coersed back to 100.
  • Continued looping of the power level will eventually get to point where both motors travel 700 counts per second.
So we get a straight line movement, just not at the desired sped.


Mon Sep 22, 2008 11:56 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: NXT Motor Speed
jmpessanha wrote:
Hi everyone,
I was using motor encoder target command to control the motors of my robot. I noticed that the movement of the motor was dependent of the batteries charge. As the turning angle must be precise I've tried to use the MotorPIDSpeedCtr command to try to avoid this unstable behviour. I'm seeing now that the two commands can be not compatible. Do you have more information on this subject? Should I change the code to control if the motor encoder was reached instead of targeting a given motor encoder directly?

Previous post described details of PID speed control -- i.e. using a PID algorithm that uses motor encoder readings as feedback to regulate the speed of a motor. It then described how the "synched motors" was an additional overlay to keep two motors moving in the same speed ratio.

This post describes the implementation for "moving a motor to stop at a precise encoder target position". This is another example of PID control; in this case the PID calculation uses the distance from the target encoder position to determine the speed of the motor. With the objective that the speed reaches 0 precisely at the target encoder position. The algorithm works as follows:
  • When "far" from the target encoder position, the normal speed control PID algorithm is reached.
  • When "close" to the target encoder position, the PID calculation changes to the above algorithm.
Synced motors are "stop at encoder position" are intended to be compatible. But it is quite possible that they don't work so well.


Tue Sep 23, 2008 12:03 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.