Let us teach Fusion to move, using the
Python equivalents of a Blockly
programming language. If we want to look
at the Python equivalent to a Blockly
program, the first thing we have to do
is to login. We will login with a username
of User1. You use whatever name and
password is appropriate for your case.
I will click login and
will get rid of our password manager,
and launch Blockly. There are a few
things we want to change.
Down the bottom we've got program output.
We do not need that. We'll get rid of that,
so we've got a bit more room for our
Python and Blockly programs.
That space has gone now.
We are also only using the Basic Commands.
These are the Intermediate Commands.
We have deleted the Intermediate
Commands. We have only got
the simple Basic Commands. When we
start up Fusion you will notice on the
left we have the Blockly Commands.
On the right we have some Python Commands.
"Import Fusion" brings in
all the routines which allow
Python to talk to a Fusion robot.
We also have "f=Fusion.driver()"
which represents the Fusion drivers which
allow Python to talk to our Fusion robot.
This heading will be needed at the
head of every one of our Python programs
that control Fusion. Now let us move down
one Blockly command.
On the right hand side
we have "import time". The speed is set to
a speed equal to 60%. The Fusion
motors M0 and M1 are set to 60%
(speed=60)
"time.sleep(1)" means that Fusion will keep the current speed
(60%) for a time of approximately
one second.
The processor goes to sleep for
one second, and the speed of 60% continues
for one second.
Next Fusion motors M0 and
M1 are both set to zero.
Both motors will be stopped. That is the end of our program.
Now run our Blockly code.
When we run the Blockly program
what were actually doing is running a
Python program. We did not know that up
until now. The system converts our Blockly
program into Python and it is this Python
program which is running.
Save the Blockly program.
Call our code Untitled4.blk
Bad choice!
See the bottom of the screen.
There is already a file of that name.
We have got to choose another name.
Try Test2.blk
A "blk" ending means Blockly.
Test2.blk is OK.
Our code saved successfully.
Fusion ran successfully.
That is pleasing.
However we can we run the Python program
by itself without using Blockly.
Let's try. Leave Blockly and
we will start up the editor for Python.
Let us launch the simple Python Programming Editor.
We already have "Import Fusion" and
have f=Fusion.driver().
Let us type in the rest of the code.
This is the whole code.
An identical program to what we had before.
However this time we have
no Blockly heading on the left-hand side.
We only have
the Python program. We can run that
by pressing the green triangle.
It will tell us to save the program.
Try Test2V1.py
This will be saved for us.
The program runs.
The Blockly program in fact transfers all
its commands into Python, but you can also run the
Python code by itself. To teach your Fusion
robot what to do, in the next tutorial
we will look at using more commands
than just this Blockly forward command.
Thank you for watching...
Không có nhận xét nào:
Đăng nhận xét