3D Rad Special Tutorials
I am not into artwork and "eye candy' special effects.
My background has always been of a technical and scientific nature, and so you will find, therefore, that my 3D projects are biased towards these fields. My tutorials, with beginners in mind, will tend towards the making of physical simulations, rather than the "game-making" side of things.
My background has always been of a technical and scientific nature, and so you will find, therefore, that my 3D projects are biased towards these fields. My tutorials, with beginners in mind, will tend towards the making of physical simulations, rather than the "game-making" side of things.
Page 1 : This page....Build and program a Mindstorms® Bot
Page 2 : RadBot.... Creation, Programming and Challenges ( NEW! 13/08/2013 )
Page 2 : RadBot.... Creation, Programming and Challenges ( NEW! 13/08/2013 )
Build and Program a Mindstorms® Bot
21/09/2011
As mentioned in my blog(21/09/2011), I am starting a series of tutorials (which will make full use of
my set of virtual robotic parts) on the basics of programming robotic machines using AngelScript. I am not a great believer in writing reams of text.......I feel that one learns more by means of practical examples and trying things out on one's own. So you will find that my tutorials will be very much example-based, with all descriptions and explanations buried in the Scripts themselves. Also, all the projects have been put together with v7.22 of 3DRad, so if you have a lower version then you will need to upgrade.
I have a general plan of how this series will evolve, but nothing definate. So there is the possibility of hiccups along the way. Anyway, enough said.......lets get on with the first tutorial, which introduces the driving power of any robotic machine......its motor.
Here is a pic of the motor we'll be using:
my set of virtual robotic parts) on the basics of programming robotic machines using AngelScript. I am not a great believer in writing reams of text.......I feel that one learns more by means of practical examples and trying things out on one's own. So you will find that my tutorials will be very much example-based, with all descriptions and explanations buried in the Scripts themselves. Also, all the projects have been put together with v7.22 of 3DRad, so if you have a lower version then you will need to upgrade.
I have a general plan of how this series will evolve, but nothing definate. So there is the possibility of hiccups along the way. Anyway, enough said.......lets get on with the first tutorial, which introduces the driving power of any robotic machine......its motor.
Here is a pic of the motor we'll be using:
And here are the project files that goes with it:

nxt_motora.3dr | |
File Size: | 151 kb |
File Type: | 3dr |

nxt_motorb.3dr | |
File Size: | 151 kb |
File Type: | 3dr |

nxt_motorc.3dr | |
File Size: | 151 kb |
File Type: | 3dr |

nxt_motord.3dr | |
File Size: | 151 kb |
File Type: | 3dr |
As you can see, four motor project files have been provided for use in these tutorials. The motors in these files will be called MotorA, MotorB, MotorC and MotorD, respectively. The files are virtually identical and show how the main parts of a motor fit together. These being 1) motor_body 2) motor_rotor 3)motor_revolutejoint and 4) motor_script. Please do not try to run the motor_script on its own.......it has to be linked to a master script in order to work. Examining the motor_script will show the reason for this.
The next step is to place the motor in a the Training Area together with a master script (called MAIN SCRIPT)
by which the basic operations (start,stop,forward,reverse and speed) of the motor can be controlled.
Remember, all explanations can be found in the scripts.
Here is a pic of this setup:
by which the basic operations (start,stop,forward,reverse and speed) of the motor can be controlled.
Remember, all explanations can be found in the scripts.
Here is a pic of this setup:
And here is the project file:

motora_in_trainingarea.3dr | |
File Size: | 344 kb |
File Type: | 3dr |
MotorA is all on its lonesome.......let's give it some company, in the form of MotorB.
And the project file:

motora_motorb_in_trainingarea.3dr | |
File Size: | 508 kb |
File Type: | 3dr |
You will note that on reading the MAIN SCRIPT for the above project, I have asked you (as an exercise in understanding) to add the remaining motors MotorC and MotorD. Please try and do so!
If you REALLY have a problem then download the following project files for the solution:

motora_motorb_motorc_in_trainingarea.3dr | |
File Size: | 630 kb |
File Type: | 3dr |

motora_motorb_motorc_motord_in_trainingarea.3dr | |
File Size: | 781 kb |
File Type: | 3dr |
Ok, that's it for an introduction to motors.........more on them later, where they will have an important role to play.
We will now head into the nitty gritty of programming robotic machines. They operate in a manner which requires a special method of programming using a software structure called a Finite State Machine (or FSM for short) A robotic machine works on a fixed sequence of actions.......one action starting only after a previous action has completed. A FSM enables this to take place. This can best be observed by means of an example project, and all is explained within the main script of the following project
We will now head into the nitty gritty of programming robotic machines. They operate in a manner which requires a special method of programming using a software structure called a Finite State Machine (or FSM for short) A robotic machine works on a fixed sequence of actions.......one action starting only after a previous action has completed. A FSM enables this to take place. This can best be observed by means of an example project, and all is explained within the main script of the following project

simplefinitestatemachine.3dr | |
File Size: | 107 kb |
File Type: | 3dr |
I am going to stop here for a bit.........while I prepare the next section of the tutorial (and give you time to digest this first section!)
A teaser for what will follow:
A teaser for what will follow:
22/09/2011
To further test your understanding of using an FSM, try out this little exercise:
1)Start MotorA
2)Let it run for 5000msec
3)Then start MotorB
4)Let both motors run for 3000msec
5)Stop both motors
Hint: Use MotorA_MotorB_in_TrainingArea.3dr as the basis. Merge in the code from SimpleFiniteStateMachine.3dr
Solution project:
1)Start MotorA
2)Let it run for 5000msec
3)Then start MotorB
4)Let both motors run for 3000msec
5)Stop both motors
Hint: Use MotorA_MotorB_in_TrainingArea.3dr as the basis. Merge in the code from SimpleFiniteStateMachine.3dr
Solution project:

applying_fsm_to_motorcontrol.3dr | |
File Size: | 510 kb |
File Type: | 3dr |
24/09/2011
DomaBot - introducing your new learning partner (that's him in the teaser above)
To be able to experiment, you need a "training bot" to which you can feed your commands, and (hopefully) be obeyed.I've chosen a very simple two-motor robot called DomaBot. It has not been designed by me.......the plans are freely available from http://www.damienkee.com/robots/. I used the 3DRad Editor and my set of virtual parts to construct the base version of DomaBot (with no attachments, at this stage). This tutorial is related to robotic programming and not robotic construction, so I have provided a pre-built DomaBot for use in this tutorial. If you have the time and patience to build your own from the plans, then do so by all means. But, let me warn you, there is much tweaking of properties required to get more or less reasonable results. I suggest you take apart my provided DomaBot to see how it all fits together and how the properties of the different parts have been set up.
Ok.....so here is the 3DRad project file using DomaBot fitted with an FSM main script. Play around with the variables and see how you go. You will probably find that it is not altogether foolproof ( I am starting to find out that the PhysX processing ability in 3DRad is not entirely ideal), but its just fine for a training environment.
To be able to experiment, you need a "training bot" to which you can feed your commands, and (hopefully) be obeyed.I've chosen a very simple two-motor robot called DomaBot. It has not been designed by me.......the plans are freely available from http://www.damienkee.com/robots/. I used the 3DRad Editor and my set of virtual parts to construct the base version of DomaBot (with no attachments, at this stage). This tutorial is related to robotic programming and not robotic construction, so I have provided a pre-built DomaBot for use in this tutorial. If you have the time and patience to build your own from the plans, then do so by all means. But, let me warn you, there is much tweaking of properties required to get more or less reasonable results. I suggest you take apart my provided DomaBot to see how it all fits together and how the properties of the different parts have been set up.
Ok.....so here is the 3DRad project file using DomaBot fitted with an FSM main script. Play around with the variables and see how you go. You will probably find that it is not altogether foolproof ( I am starting to find out that the PhysX processing ability in 3DRad is not entirely ideal), but its just fine for a training environment.

domabot_base_with_motorscript.3dr | |
File Size: | 1467 kb |
File Type: | 3dr |
25/09/11
BUG ALERT!:
I've discovered a small bug in my wait() function which was giving DomaBot some grief !
Please replace the line:
if (TimeElapsed==numMilliSec)
with:
if (TimeElapsed>=numMilliSec)
in the following projects:
simplefinitestatemachine.3dr
applying_fsm_to_motorcontrol.3dr
domabot_base_with_motorscript.3dr
I have re-uploaded all the above files
I've discovered a small bug in my wait() function which was giving DomaBot some grief !
Please replace the line:
if (TimeElapsed==numMilliSec)
with:
if (TimeElapsed>=numMilliSec)
in the following projects:
simplefinitestatemachine.3dr
applying_fsm_to_motorcontrol.3dr
domabot_base_with_motorscript.3dr
I have re-uploaded all the above files
You will no doubt have noticed that to make DomaBot run forward we had to give it a negative Speed parameter in the motor() function. This is clearly undesirable and also rather confusing, so to rid this I had to make a "mechanical" adjustment to DomaBot itself. DomaBot will now run forward if you give it a positive Speed command, and will reverse if you give a negative Speed command.
The final stage in motor control, is to enable DomaBot to turn. There are two types of turn :
1) A "turn-in-place" or "point turn", where one motor drives its wheel forward and the other motor drives its wheel backward.
2)A "swing turn", where one motor drives its wheel forward and the other motor is stopped.
Here is a summary of all the motor commands:
1) A "turn-in-place" or "point turn", where one motor drives its wheel forward and the other motor drives its wheel backward.
2)A "swing turn", where one motor drives its wheel forward and the other motor is stopped.
Here is a summary of all the motor commands:
And here is a project showing DomaBot's turning action (and for you to add to !). Please note that from now on this project wll be used as a template for future projects.

domabot_base_with_turning.3dr | |
File Size: | 1468 kb |
File Type: | 3dr |
26/09/2011
At the present time, DomaBot is really just a moving vehicle, with no ability to sense anything in the "real" world. A robotic machine has to be fitted with sensors which will provide it with feedback so that it can make decisions and take appropiate action. So as a first step, let's give DomaBot the sense of Touch. The L_NXTTouchSensor_Switch and L_NXTTouchSensor_Body are the RigidBody parts which have been provided for this purpose. They are used in combination, together with a Slider type joint. Again, to save on unneccesary building work for you, I have provided a pre-built TouchSensor attachment for DomaBot.
Part of the attachment has been built within the 3DRad Editor. The part NOT built in the 3DRad Editor is the RigidBody part which I've called the DomaBot_TouchTrigger:
DomaBot_TouchTrigger

I built this part using my favourite 3D Modeller, as I wanted it to be one complete RigidBody. The part hinges on the main attachment, and triggers the L_NXTTouchSensor_Switch when pushed.
Please add it to your 3DRad Rigidbody data library.

domabot_touchtrigger.zip | |
File Size: | 58 kb |
File Type: | zip |
While in the process of building the attachment, I noticed that the L_NXTTouchSensor_Switch (as provided in my set of virtual parts) was not quite correct. So please overwrite your original part with this updated part:

l_nxttouchsensor_switch.zip | |
File Size: | 17 kb |
File Type: | zip |
And here is your example project showing how DomaBot is programmed to make use of its new Touch Sensor:

domabot_base_with_touchsensor.3dr | |
File Size: | 1971 kb |
File Type: | 3dr |
01/10/2011
I've now added a LightSensor attachment to DomaBot:
A real-world sensor of this type can sense light brightness ranging from dark to bright, returning a value dependent on the amount of light. However, due to some limitations in 3DRad, the "light" value which is read by the LightSensor is simulated by a little trickery. This does not deviate from the main purpose of this tutorial, which is to teach robotic programming.
The example which is provided for you to study demonstrates using the LightSensor to detect black lines drawn on the floor surface. You have probably found in the previous examples that DomaBot can easily fall off the edge of the floor surface, if not controlled carefully. By drawing a black line border around the perimeter of the floor, and with the aid of the aid of the LightSensor, you can restrict DomaBot's activities to within the border area.
The first thing to do is add the DomaBot_LineSquare skinmesh to your 3DRad SkinMesh data library:
The example which is provided for you to study demonstrates using the LightSensor to detect black lines drawn on the floor surface. You have probably found in the previous examples that DomaBot can easily fall off the edge of the floor surface, if not controlled carefully. By drawing a black line border around the perimeter of the floor, and with the aid of the aid of the LightSensor, you can restrict DomaBot's activities to within the border area.
The first thing to do is add the DomaBot_LineSquare skinmesh to your 3DRad SkinMesh data library:

domabot_linesquareborder.zip | |
File Size: | 5 kb |
File Type: | zip |
Next, download the following two demonstration projects:

domabot_base_with_lightsensor.3dr | |
File Size: | 1796 kb |
File Type: | 3dr |

domabot_base_loopforever.3dr | |
File Size: | 1797 kb |
File Type: | 3dr |
The code also shows how the Main routine has been made more manageable by converting common repeated movements into smaller sub-functions which can which can be called by Main when required.
These sub-functions are named as follows:
straight_forward(Speed) - Move forward forever at required Speed
straight_reverse(Speed) - Move backward forever at required Speed
stop() - Stop movement
timed_forward(Speed,Period) - Move forward at Speed for required Period
timed_reverse(Speed,Period) - Move backward at Speed for required Period
timed_leftturn(Speed,Period) - Turn left at Speed for required Period
timed_rightturn(Speed,Period) - Turn right at Speed for required Period
These sub-functions are named as follows:
straight_forward(Speed) - Move forward forever at required Speed
straight_reverse(Speed) - Move backward forever at required Speed
stop() - Stop movement
timed_forward(Speed,Period) - Move forward at Speed for required Period
timed_reverse(Speed,Period) - Move backward at Speed for required Period
timed_leftturn(Speed,Period) - Turn left at Speed for required Period
timed_rightturn(Speed,Period) - Turn right at Speed for required Period
11/10/2011
Using the LightSensor, DomaBot can be made to follow a line drawn on the floor surface.
On entering the righthand edge of the black line, DomaBot will forward turn towards its right, and on exiting the righthand edge of the black line DomaBot will forward turn towards its left............thus always keeping just to the righthand edge of the line.
A new "curve_forward()" function has been added to enable the above actions.
curve_forward(SpeedA,SpeedB) - Enable a curved forward motion by applying
different SpeedA and SpeedB to the resp.
motors.
The first thing to do is add the DomaBot_LineCurve skinmesh to your 3DRad SkinMesh data library:
A new "curve_forward()" function has been added to enable the above actions.
curve_forward(SpeedA,SpeedB) - Enable a curved forward motion by applying
different SpeedA and SpeedB to the resp.
motors.
The first thing to do is add the DomaBot_LineCurve skinmesh to your 3DRad SkinMesh data library:

domabot_curvedline.zip | |
File Size: | 7 kb |
File Type: | zip |
And the project file:

domabot_linefollower.3dr | |
File Size: | 2011 kb |
File Type: | 3dr |
24/10/2011
Up until this point, DomaBot has only been able to sense something by actually bumping into it (TouchSensor) or by crossing it (LightSensor). We would like DomaBot to sense an obstruction before making contact with it, so that avoiding action can be taken. For this case, an UltraSonicSensor is provided. The UltraSonicSensor is used to enable DomaBot to "see" objects in its path, and then take action to avoid them. It makes use of the 3DRad "Scanner" object which operates in a similar fashion to a real UltraSonicSensor. That is,by sending out an an ultrasonic beam and measuring the time taken for the reflected signal to return, the distance to
the intercepting object is determined.The 3DRad "Scanner" simulates the beam by means of a "ray" vector.
the intercepting object is determined.The 3DRad "Scanner" simulates the beam by means of a "ray" vector.
And the demo project:

domabot_base_with_ultrasonicsensor.3dr | |
File Size: | 1937 kb |
File Type: | 3dr |
01/11/2011
Most robotic machines have some form of manipulator by which they can handle objects. DomaBot is no exception, and I have equipped him with a pair of grippers (controlled via a third motor, MotorC). I have also
given him a second UltraSonicSensor (two "eyes" are better than one !)
given him a second UltraSonicSensor (two "eyes" are better than one !)
This program sample is a little more complex than the previous program samples.It demonstrates how DomaBot can be made to locate an object (a ball, in this example) and position itself so that it can open its grippers and grasp the ball, then carry the ball to another location where it releases the ball.
It was neccessry to add 3 more sub-functions, namely:
open_gripper(Speed,Period) - Open the gripper at Speed for required
Period.
close_gripper(Speed,Period) - Close the gripper at Speed for required
Period.
inplace_turn(Speed) - Perform continual in-place turn at
Speed.
SOME ADVICE: Prior to writing any code, it is always best to put down in writing what you want your program to accomplish. Then break this down into a list of consecutive action steps and the conditions for each action step advance to the next step. This list can then be used to write the code where each "case" statement in the FSM is an action step utilising one of the sub-functions. Document your program with adequate comments which clarify each step (as I have done in this example).This makes it so much
easier for others to read your program, and for yourself to refer to later when,perhaps,your memory is not as clear!
Here is the sample project:
It was neccessry to add 3 more sub-functions, namely:
open_gripper(Speed,Period) - Open the gripper at Speed for required
Period.
close_gripper(Speed,Period) - Close the gripper at Speed for required
Period.
inplace_turn(Speed) - Perform continual in-place turn at
Speed.
SOME ADVICE: Prior to writing any code, it is always best to put down in writing what you want your program to accomplish. Then break this down into a list of consecutive action steps and the conditions for each action step advance to the next step. This list can then be used to write the code where each "case" statement in the FSM is an action step utilising one of the sub-functions. Document your program with adequate comments which clarify each step (as I have done in this example).This makes it so much
easier for others to read your program, and for yourself to refer to later when,perhaps,your memory is not as clear!
Here is the sample project:

domabot_with_gripper.3dr | |
File Size: | 2368 kb |
File Type: | 3dr |
Back to My Little Shop