Sensors return values, types and more :D Newbie
-
- Posts: 6
- Joined: 11 Feb 2011, 11:35
Sensors return values, types and more :D Newbie
Hello
I'm still fairly new to NXC so please forgive the questions.
1) First of all I would like to know what type of values are returned by the sensors.
I know that the US sensor returns bytes in (0, 255) but can it return any other types?
What type of values does the color sensor return (in both color and light mode)?
Maybe someone could provide me with some links, pdf (I already checked the tutorial PDF and it is not very complex, guide PDF and API are, on the other hand, a bit complicated at this stage)?
2) I would like my robot to do precise turns (for example 45, 90, 120 degrees) on any kind of surface (this is important). I know that you can synchronise the motors in forward// backward movement and that there are many functions connected with motors with different input values. Can someone give me a tip/ hint on how to implement such turns? Is it even possible?
3) How do you guys handle multitasking? I've seen m-goldberg's tutorial, I know mutex more or less, I know how to use start/stop. As far as I know mutex allows only one task to be executed at a moment, then next in line can be done etc. What to you do when you have a following problem:
You have a program that has 5 tasks. Let's say it drives a robot around and does some stuff. If a certain action occurs (i.e touch sensor is pressed) you want only 3 tasks to work at the same time, then you want only 2 tasks to work and finally again all task should be working. Jumping across the tasks using start/stop does not seem to be te most effective solution.
The mulititasking concept is still a bit shady for me (when the program is more complex then, say 4 - 5 tasks), maybe you could give me some advice, provide some links?
Many thanks for any reply
Michal
I'm still fairly new to NXC so please forgive the questions.
1) First of all I would like to know what type of values are returned by the sensors.
I know that the US sensor returns bytes in (0, 255) but can it return any other types?
What type of values does the color sensor return (in both color and light mode)?
Maybe someone could provide me with some links, pdf (I already checked the tutorial PDF and it is not very complex, guide PDF and API are, on the other hand, a bit complicated at this stage)?
2) I would like my robot to do precise turns (for example 45, 90, 120 degrees) on any kind of surface (this is important). I know that you can synchronise the motors in forward// backward movement and that there are many functions connected with motors with different input values. Can someone give me a tip/ hint on how to implement such turns? Is it even possible?
3) How do you guys handle multitasking? I've seen m-goldberg's tutorial, I know mutex more or less, I know how to use start/stop. As far as I know mutex allows only one task to be executed at a moment, then next in line can be done etc. What to you do when you have a following problem:
You have a program that has 5 tasks. Let's say it drives a robot around and does some stuff. If a certain action occurs (i.e touch sensor is pressed) you want only 3 tasks to work at the same time, then you want only 2 tasks to work and finally again all task should be working. Jumping across the tasks using start/stop does not seem to be te most effective solution.
The mulititasking concept is still a bit shady for me (when the program is more complex then, say 4 - 5 tasks), maybe you could give me some advice, provide some links?
Many thanks for any reply
Michal
Re: Sensors return values, types and more :D Newbie
hi,
maybe it could be useful if you read this tutorial first:
http://bricxcc.sourceforge.net/nbc/nxcd ... torial.pdf
HTH!
maybe it could be useful if you read this tutorial first:
http://bricxcc.sourceforge.net/nbc/nxcd ... torial.pdf
HTH!
-
- Posts: 6
- Joined: 11 Feb 2011, 11:35
Re: Sensors return values, types and more :D Newbie
Hi doc-helmut, thank you for your reply.
I've already checked that tutorial, it gives a simple example on multitasking, but I would like to know how to handle more complex tasks, as I described above.
I've reed about synchronising motors in forward and bacward movement. I'm more interested in how to do (if it's possible) precise turns.
Also it would be very helpful for me to know the possible outputs of US and color sensors.
Michal
I've already checked that tutorial, it gives a simple example on multitasking, but I would like to know how to handle more complex tasks, as I described above.
I've reed about synchronising motors in forward and bacward movement. I'm more interested in how to do (if it's possible) precise turns.
Also it would be very helpful for me to know the possible outputs of US and color sensors.
Michal
Re: Sensors return values, types and more :D Newbie
then maybe this file could be helpful:
http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_Guide.pdf
the US sensor has no other output format (the US value = distance in cm)
in other cases: post your specific code and we will see if we can help you!
http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_Guide.pdf
the US sensor has no other output format (the US value = distance in cm)
in other cases: post your specific code and we will see if we can help you!
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Sensors return values, types and more :D Newbie
Helmut is right, the ultrasonic sensor reads in cm. However, if you want it in inches (or some other measurement), the NXT just needs to do a little math (cm to inches, multiply by 2.54, or 254 and divide by 100 if you don't have floating point support).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 6
- Joined: 11 Feb 2011, 11:35
Re: Sensors return values, types and more :D Newbie
OK What about color sensor? What output does it give (with types)?
As far as the turning problem goes I would love to provide some code, the problem is I don't even have any concept on how to implement such turns, that is why I'm asking. I guess I could deal with the coding itself, I only need some guidance with the logic, possible functions to use, solutions, tips etc.
So again: I would like my robot to take 90 degrees turns on a carpet, on a floor, or any other surface, is it possible to implement?
Michal
As far as the turning problem goes I would love to provide some code, the problem is I don't even have any concept on how to implement such turns, that is why I'm asking. I guess I could deal with the coding itself, I only need some guidance with the logic, possible functions to use, solutions, tips etc.
So again: I would like my robot to take 90 degrees turns on a carpet, on a floor, or any other surface, is it possible to implement?
Michal
Re: Sensors return values, types and more :D Newbie
yes, it's possible (more or less exactly), but what you need to do is not to make the 2nd step before the first one.I would like my robot to take 90 degrees turns on a carpet, on a floor, or any other surface, is it possible to implement?
Try some easier codes, make some experiments by yourself, read different tutorials, buy (or borrow) some books, change the given programs a little to improve them or adjust them to your wishes, learn by doing.
Rome hasn't been built in just 1 day (as we say), neither will be your programming skills. You will only learn if you'll do it by yourself: step for step, word for word, line for line, function by function.
If you once will be able have some code of your own: show us, we'll gladly help you along!
Re: Sensors return values, types and more :D Newbie
Hi Michal,michal2195 wrote:Hello
3) How do you guys handle multitasking? I've seen m-goldberg's tutorial, I know mutex more or less, I know how to use start/stop. As far as I know mutex allows only one task to be executed at a moment, then next in line can be done etc. What to you do when you have a following problem:
You have a program that has 5 tasks. Let's say it drives a robot around and does some stuff. If a certain action occurs (i.e touch sensor is pressed) you want only 3 tasks to work at the same time, then you want only 2 tasks to work and finally again all task should be working. Jumping across the tasks using start/stop does not seem to be te most effective solution.
The mulititasking concept is still a bit shady for me (when the program is more complex then, say 4 - 5 tasks), maybe you could give me some advice, provide some links?
Many thanks for any reply
Michal
More exactly, a mutex only allows one task to control a shared resource at a time. So for example, if you have 3 tasks, and all of them have a code that may try to control the motors, then you have a mutex for the motors, and whenever a task has code that tried to control the motors, you make it request the mutex. So all of your tasks are happening simultaneously, but only one of them can enter into the section of code that controls the motors. So for example,
mutex motormutex;
Task1:
code doing some stuff, checking sensor values
request the motor mutex
control the motors
release the motor mutex
code doing other stuff
Task2:
code doing some stuff, checking sensor values
request the motor mutex
control the motors
release the motor mutex
code doing other stuff
Now the key here is that task 1 and task 2 are both running, but whichever one gets to the motor mutex first gets it.
Finally, if you want any of your tasks to not run until the touch sensor is touched, then you wouldn't use the start/stop task command, you'd put a while command around the loop and do while the touch sensor is false.
Hope that helped!
Cheers,
Kami
I haven't grown past my playing with Legos stage and I don't think I want to
Blog: http://nuhlikklebickle.blogspot.com
Kami
Blog: http://nuhlikklebickle.blogspot.com
Kami
Re: Sensors return values, types and more :D Newbie
I would first ask why on earth would you want a program with 5 tasks? You will be a lot better off sticking with programs that have just 1 task for quite a long time. Maybe two or three if you really get adventurous.
More often than not you should do as much as you possibly can on a single task.
John Hansen
More often than not you should do as much as you possibly can on a single task.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 6
- Joined: 11 Feb 2011, 11:35
Re: Sensors return values, types and more :D Newbie
Thank you lizard381, that helped me understand mutex better.
As far as the task number I'll follow John's advice and try to keep it as low as possible.
Thanks
As far as the task number I'll follow John's advice and try to keep it as low as possible.
Thanks
Who is online
Users browsing this forum: No registered users and 0 guests