Author |
Message |
The_JD
Rookie
Joined: Sat Oct 04, 2008 2:30 pm Posts: 7
|
 Retrieving Values From Motors
Hi,
I'm using the Lego NXT Mindstorms kit to make an advanced Line Tracker. I know its beginner stuff but thats what I am. Anyways, I need to know if it is possible to read and store the values from one of the motors.
Basically, I'm using the line sensor to get the robot to track a circle. After one complete rotation (i.e. tracking the circle and returning to its starting point on the circumference), the robot switches off it's light sensor and attempts to follow the circle once more. The way I'm trying to do this is to get the robot to store the values of the motor from the first time it went around the circle and then implement those the second time when it attempts to do it without the light sensor.
I know there are a lot of possible flaws in this logic etc. but its a good learning curve and so I just need to know if its possible to be able to read the values of the motors and store them for future use. Sort of like a scanf function but for a motor. Any help or advice in this matter is much appreciated.
Regards,
JD.
|
Fri Oct 17, 2008 10:14 am |
|
 |
basicxman
Rookie
Joined: Sun Sep 28, 2008 1:06 pm Posts: 27
|
 Re: Retrieving Values From Motors
Are you trying to get the encoder values? nMotorEncoder[motorA]; //substitute 'A' with what motor port you wish
That variable will retrieve how many degrees the said motor is turning.
|
Fri Oct 17, 2008 8:24 pm |
|
 |
The_JD
Rookie
Joined: Sat Oct 04, 2008 2:30 pm Posts: 7
|
 Re: Retrieving Values From Motors
Hmmm... I'm not too sure. In my program, I just use lines like 'motor[motorA] = 35;'. What value is it that I'm assigning here? I'm pretty sure its not the encoders.
|
Mon Oct 20, 2008 11:22 am |
|
 |
Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030
|
 Re: Retrieving Values From Motors
no, motor(motorA)=35 means the power level (35%) = sort of 35% speed
_________________ regards, HaWe aka Ford #define S sqrt(t+2*i*i)<2 #define F(a,b) for(a=0;a<b;++a) float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}
|
Mon Oct 20, 2008 11:32 am |
|
 |
Jeff McBride
Professor
Joined: Fri Sep 19, 2008 1:22 am Posts: 200
|
 Re: Retrieving Values From Motors
If I understand you correctly, you are adjusting the power to the motors as part of a line following program and want to record the right and left power levels periodically as a table of data to be "replayed" for subsequent loops around the course. If that is the case then I suggest looking into the Datalog feature. You can retrieve the current power level for a motor by using the motor[] array on the right side of an assignment statement like so:
currentPower = motor[motorA];
So, in your line-following code just log the right and left power levels on each itteration (or every n itterations) of the loop.
Then, run though the logged data over and over setting the motor power levels to the recorded values.
_________________ Jeff McBride Benson Robotics Club
|
Mon Oct 20, 2008 1:15 pm |
|
 |
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 616
|
 Re: Retrieving Values From Motors
Beginner stuff is the simple line follower -- one motor turned on and the other motor turned off depending on bnary value of which side of the line edge the light sensor is detecting. You can do true "post-graduate" education level work with more sophisticated algorithms that use variable speed for the motors and use the analog values of the light sensor. Or use multiple light sensors.
|
Wed Oct 22, 2008 6:22 am |
|
 |
The_JD
Rookie
Joined: Sat Oct 04, 2008 2:30 pm Posts: 7
|
 Re: Retrieving Values From Motors
Thanks for the replies guys. Using more than one light sensor was my initial idea but unfortunately, we've been restricted to one and (in my case, eventually none).
The datalogging function seems to be quite handy though. However, is there a way to retrieve the values from the log? I now know how to write to the log but how can I retrieve those values ot be used later in the same program?
- JD.
|
Thu Oct 23, 2008 5:51 pm |
|
 |
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 616
|
 Re: Retrieving Values From Motors
If you want to retrieve during program run, then why not store the data points in a array?
|
Thu Oct 23, 2008 11:21 pm |
|
 |
The_JD
Rookie
Joined: Sat Oct 04, 2008 2:30 pm Posts: 7
|
 Re: Retrieving Values From Motors
Thanks for all the help guys. Using datalog to write the values into an array and calling them in sequence was the easiest and least painful way to do it.
- JD.
|
Sat Oct 25, 2008 3:11 pm |
|
|