NXT writing project
-
- Posts: 3
- Joined: 14 Aug 2011, 04:55
NXT writing project
Hi, how are you, I apologize if my English is a little obscure, but I hope you understand the thread. I'm a NXT beginner and I decided to make a college project with a Lego robot. The hardware is based on the Sudoku Solver project (I expect some of the forum people know the project, here is the sudoku's page: http://tiltedtwister.com/sudokusolver.html), but I only want it to write a determined english sentence, so I'm only interested in the writing proceeding. Well, as in the solver, the robot movements for writing a specific letter are done by calling it from a command string, for example "uudddddllrrrr" where u is up, d is down,etc. Despite I can write the letter I have had some problems:
- First I'm trying, without success, to obtain a precise rotation movement using the RotateMotorExPID, but I dont have so clear how to do it. What I'm doing is calling, with a for loop, the characters from the string one by one; so I call ,for example, an 'u' then I go to a task where I move the motor and see how much did it move with the MotorRotationCount , reset the tacho and uses these information in the RotateMotorExPID. But I don't really know how to calculate de PID constants, since I don't have the motor equation as a plant, and the robot has an unexpected response, similar to an oscillating system.
- Also, the robot doesn't write the phrase over a straight line, despite I program it to return to a reference point after writing every letter; do you have any idea how I could get this response?
- ¿Does exist any form, using Bricx, to move two motors simultaneously, with different angles and/or powers ?
- At least, I want to ask you as a favor if you have some ideas in order to improve my project. For example if I want to write more than one phrase, which do you think is the better way to choose one of them? I was thinking about using the ultrasonic sensor for measuring different distances ranges, where each one represents one of the phrases; but I realize it isn't a refined solution. Could you say me other ways to increase my project's difficulty? for example I saw a little of Robotics, but I couldn't find any part in my project for using, for example, inverse kinematics, then I think my project is too simple and maybe I won't get the grade I want.
So, if it isn't a nuisance for you, it would be great if you can help me with ideas or anything, thanks for your answers.
PD: I know my English is really poor, if you don't understand something please let me know.
- First I'm trying, without success, to obtain a precise rotation movement using the RotateMotorExPID, but I dont have so clear how to do it. What I'm doing is calling, with a for loop, the characters from the string one by one; so I call ,for example, an 'u' then I go to a task where I move the motor and see how much did it move with the MotorRotationCount , reset the tacho and uses these information in the RotateMotorExPID. But I don't really know how to calculate de PID constants, since I don't have the motor equation as a plant, and the robot has an unexpected response, similar to an oscillating system.
- Also, the robot doesn't write the phrase over a straight line, despite I program it to return to a reference point after writing every letter; do you have any idea how I could get this response?
- ¿Does exist any form, using Bricx, to move two motors simultaneously, with different angles and/or powers ?
- At least, I want to ask you as a favor if you have some ideas in order to improve my project. For example if I want to write more than one phrase, which do you think is the better way to choose one of them? I was thinking about using the ultrasonic sensor for measuring different distances ranges, where each one represents one of the phrases; but I realize it isn't a refined solution. Could you say me other ways to increase my project's difficulty? for example I saw a little of Robotics, but I couldn't find any part in my project for using, for example, inverse kinematics, then I think my project is too simple and maybe I won't get the grade I want.
So, if it isn't a nuisance for you, it would be great if you can help me with ideas or anything, thanks for your answers.
PD: I know my English is really poor, if you don't understand something please let me know.
Re: NXT writing project
This sounds very like the same problem as programming a cnc machine and there are several NXT models of those, so why not search for 'Lego cnc' or 'NXT cnc'.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
Re: NXT writing project
¿ just a guess, are you from Spain?^^- ¿Does exist any form, using Bricx, to move two motors simultaneously, with different angles and/or powers ?
well, there indeed is a way using e.g. RotateMotorEx, but aside from sync ratios like 100, 50, 0, -50, -100 the results are actually unpredictible, weird, and odd.
Better use consecutive single motor cmds for each single motor independed from the other one.
did you already try absolute rotation targets instead of relative ones?- Also, the robot doesn't write the phrase over a straight line, despite I program it to return to a reference point after writing every letter; do you have any idea how I could get this response?
Re: NXT writing project
Don't use RotateMotorExPID then, stick to RotateMotorEx.legofromkitu wrote: ... RotateMotorExPID. But I don't really know how to calculate de PID constants, since I don't have the motor equation as a plant, and the robot has an unexpected response, similar to an oscillating system.
As doc-helmut already said: You can use RotateMotorEx with two motors and in synced mode. But the ratio parameter (called turnratio or turnpct) should be 0 for absolute correct movement. Other ratios are unreliable or unpredictable, depending on power and other parameters.legofromkitu wrote: - ¿Does exist any form, using Bricx, to move two motors simultaneously, with different angles and/or powers ?
[/quote]
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
-
- Posts: 3
- Joined: 14 Aug 2011, 04:55
Re: NXT writing project
h-g-t:
Thanks for the recommendation, I will see for the cnc.
doc-helmut:
No dude, I'm from Ecuador; I haven't practice my English as I should so I'm with problems now . I'm actually using single motor commands for writing the letters, but when I have to draw an oblique line, for example in a "x", the line appears as a ladder. Because that I want to drive independently two motors at the same time.
I didn't use absolute rotation targets, but I can't see it so clear
Linusa:
If I don't use the RotateMotorExPID, I need to write a PID algorithm, do you know how can I obtain the motor parameters?
Thanks to all for the answers
Thanks for the recommendation, I will see for the cnc.
doc-helmut:
No dude, I'm from Ecuador; I haven't practice my English as I should so I'm with problems now . I'm actually using single motor commands for writing the letters, but when I have to draw an oblique line, for example in a "x", the line appears as a ladder. Because that I want to drive independently two motors at the same time.
I didn't use absolute rotation targets, but I can't see it so clear
Linusa:
If I don't use the RotateMotorExPID, I need to write a PID algorithm, do you know how can I obtain the motor parameters?
Thanks to all for the answers
Re: NXT writing project
You can use the RotateMotorEx command for one motor in one task, and for another motor in another task. Then they're driving independently. The version with "one call to RotateMotorEx, with OUT_BC (or so)" drives them both, but not independently (they're actually synced then).legofromkitu wrote: Because that I want to drive independently two motors at the same time.
RotateMotorEx is just a simpler version of RotateMotorExPID. With RotateMotorExPID, you manually set the P,I,D params, which are left at their defaults with RotateMotorEx. Use RotateMotorEx, since setting the P I D params can mess up your motor control (you may need to restart your brick).legofromkitu wrote: If I don't use the RotateMotorExPID, I need to write a PID algorithm, do you know how can I obtain the motor parameters?
Internally, both versions use some sort of "position hold" to reach their target, see this picture: http://www.mindstorms.rwth-aachen.de/tr ... tateEx.png . There are oscillations around the target position, but that's unfortunately by design.
There is currently no way to achieve better / smother motor control with built-in NXC functions. You can however write your own controller, yes. You could also use the algorithm and motor functions from MotorControl, but they're quite bloated (32kb extra program size on your NXT's flash disk) and need some CPU time during braking. The trick is that these functions use a PID controller to control speed during deceleration, leading to fairly accurate position control AND to a smooth "natural" motor stop. For more detail, see http://www.mindstorms.rwth-aachen.de/tr ... torControl .
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
-
- Posts: 3
- Joined: 14 Aug 2011, 04:55
Re: NXT writing project
Thanks linusa, I saw your links, they were very useful for me. My project has advanced correctly, so now my robot can write the phrases accurately, but one problem persists: I have three messages and I'm using the 9V ultrasonic sensor to decide which one will be shown. The code of this program section (a task called sensor) is:
Message_1,_2 and _3 are the tasks where the different messages are defined.
Doing this, I can't obtain the correct response from the robot, I guess it could be that I have two mutex variables, one called key1 that I use in the task sensor and other one called key2 that I use in the message's tasks. However I haven't found in any document if this hypothetical conflict actually exists. Now I'm not sure why the robot can't go to the writing task I want using this algorithm. ¿Could it be a problem in the messages tasks, which work well when are called without using the sensor?
Regards to everyone.
Code: Select all
mutex key1;
task sensor(){
SetSensorLowspeed(IN_1);
if ((SensorUS(IN_1) < 25) && (SensorUS(IN_1) >= 20))
{
Acquire(key1);
Precedes (message_1);
Release(key1);
}
if ((SensorUS(IN_1) < 30) && (SensorUS(IN_1) >= 25))
{
Acquire(key1);
Precedes (message_2);
Release(key1);
}
if ((SensorUS(IN_1) < 35) && (SensorUS(IN_1) >= 30))
{
Acquire(key1);
Precedes (message_3);
Release(key1);
}
Doing this, I can't obtain the correct response from the robot, I guess it could be that I have two mutex variables, one called key1 that I use in the task sensor and other one called key2 that I use in the message's tasks. However I haven't found in any document if this hypothetical conflict actually exists. Now I'm not sure why the robot can't go to the writing task I want using this algorithm. ¿Could it be a problem in the messages tasks, which work well when are called without using the sensor?
Regards to everyone.
Last edited by legofromkitu on 17 Aug 2011, 16:10, edited 1 time in total.
Re: NXT writing project
First of all, please use [ code ] tags around your source, makes it easier to read.
Now, I don't know that much about the Precedes() command, but I think you might be using it the wrong way. AFAIK it's supposed to be used only once in every program. You put it into main(), and it basically just launches all tasks -- sort of...
Task management in NXC is difficult, as in: "better don't start and stop tasks dynamically". Make sure all tasks you need keep running all the time, and everything is cool. If you use Wait() in a task, it will "free" this CPU for other tasks, so no problem...
Apart from that: Using mutexes is "atomic", that's what they're there for. If you don't do anything logically wrong, mutexes will work as expected. Different words for "acquire" and "release" are "lock" and "unlock" (just so you get a clearer picture).
Now, I don't know that much about the Precedes() command, but I think you might be using it the wrong way. AFAIK it's supposed to be used only once in every program. You put it into main(), and it basically just launches all tasks -- sort of...
Task management in NXC is difficult, as in: "better don't start and stop tasks dynamically". Make sure all tasks you need keep running all the time, and everything is cool. If you use Wait() in a task, it will "free" this CPU for other tasks, so no problem...
Apart from that: Using mutexes is "atomic", that's what they're there for. If you don't do anything logically wrong, mutexes will work as expected. Different words for "acquire" and "release" are "lock" and "unlock" (just so you get a clearer picture).
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
Who is online
Users browsing this forum: No registered users and 1 guest