Lego Mindstorms EV3 Basic - "Ease-In, Ease-Out" Motions for Motors

So what's this EV3 Basic, anyway?

[View:https://www.youtube.com/watch?v=myFKfOA4XbQ]

This awesome extension comes from Reinhard Grafl with a ton of tooling, and the content support was created by Nigel Ward:

Get Started:

"Ease-In, Ease-Out" Motions for Motors

EV3 Basic features a new Motors object that's added to the Small Basic library!

That includes an amazing set of 15 methods! And it gives you a lot more strength and power over your machines!

Let's dig into the methods!

You can also find the Motors reference section in the EV3 Basic site.

Motor

Note that EV3 Basic makes no distinction between large and medium motors.

The Motor commands control the motors connected to the brick. For every command you need to specify one or more motor ports that should be affected (for example, "A", "BC", "ABD"). When additional bricks are daisy-chained to the master brick, address the correct port by adding the layer number to the specifier (for example, "3BC", "2A"). In this case only the motors of one brick can be accessed with a single command.

Speed vs. Power: When requesting to drive a motor with a certain speed, the electrical power will be permanently adjusted to keep the motor on this speed regardless of the necessary driving force (as long as enough power can be provided). When requesting a certain power instead, the motor will just be provided with this much electrical power and the actual speed will then depend on the resistance it meets. The normal choice in EV3 Basic should be speed.

The following table summarises the nine commands that can be used to make motors move:

 

Move x degrees (program waits for completion) Start to run indefinitely Start to move x degrees
Regulate speed Motor.Move Motor.Start Motor.Schedule
Choose power Motor.MovePower Motor.StartPower Motor.SchedulePower
Synchronize Motor.MoveSync Motor.StartSync Motor.ScheduleSync

The four highlighted commands are the most basic ones, the ones beginners will use most of the time.

To make one motor turn through a given angle or make two motors turn at the same speed through a given angle (as for straight line motion), prefer Motor.Move.

To make the robot follow a curved path for a given angle of wheel rotation (two motors moving with different speeds), prefer Motor.MoveSync. This function causes program execution to pause until the movement completes. This function is equivalent to the 'move tank' block of the standard Lego software.

To make motors turn for a given length of time, turn them on with Motor.Start (to give motors the same speed) or Motor.StartSync (to give motors different speeds), then use Program.Delay to make the program wait the desired time, then stop the motors with Motor.Stop.

 

When you have to change power or speed of an already running motor, just re-issue a Start() command with the appropriate speed or power value. The motor will then seamlessly switch over to the new mode of operation.

For all the motor commands:

  • port(s) = Motor port name(s). E.g. "BC"
  • degrees = Number of degrees to move the motor. Motor commands will always use the absolute value of the degree parameter (in other words any negative sign will be ignored), so if you want the motor to turn backwards give it a negative power or speed rather than a negative angle.
  • brake = "True", if the motor(s) should switch on the brake after movement
  • speed = speed from -100 (full reverse) to 100 (full forward)
  • power = Power level from -100 (full reverse) to 100 (full forward)

Motor.GetCount (port)
Query the current rotation count of a single motor. As long as the counter is not reset it will accurately measure all movements of a motor, even if the motor is driven by some external force while not actively running.

Returns  The current rotation count in degrees.

Motor.GetSpeed (port)
Query the current speed of a single motor.

Returns  Current speed in range -100 to 100

Motor.IsBusy (ports)
Checks if one or more motors are still busy with a scheduled motor movement.

Returns  "True" if at least one of the motors is busy, "False" otherwise.

Motor.Move (ports, speed, degrees, brake)
Move one or more motors with the specified speed through the specified angle (in degrees). This command will cause the program to pause until the motor has reached its destination. When you need finer control over the movement (soft acceleration or deceleration), consider using the command Motor.SchedulePower instead. For the difference between 'speed' and 'power', see the beginning of this Motor section.

speed Speed level from -100 (full reverse) to 100 (full forward)

degrees  The angle to rotate. Any negative sign will be ignored.

Motor.MovePower (ports, power, degrees, brake)
Move one or more motors with the specified power the specified angle (in degrees). This command will block execution until the motor has reached its destination. When you need finer control over the movement (soft acceleration or deceleration), consider using the command Motor.SchedulePower() instead.

power Power level from -100 (full reverse) to 100 (full forward)

degrees  The angle to rotate. Any negative sign will be ignored.

Motor.MoveSync (ports, speed1, speed2, degrees, brake)
This function is similar to the 'Move Tank' block in the standard Lego EV3 software. Moves 2 motors (with speeds that can be different) a defined number of degrees. The angle to move will be measured at the motor with the higher speed. This function pauses program execution until the movement completes. If you want the movement to return immediately you should use Motor.ScheduleSync() instead. The two motors are synchronized which means that when one motor experiences some resistance and can not keep up its speed, the other motor will also slow down or stop altogether. This is especially useful for vehicles with two independently driven wheels which still need to go straight or make a specified turn.

ports  Names of exactly TWO motor ports (for example "AB" or "CD")

speed1  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.

speed2  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.

degrees  The angle that the faster motor should rotate. Any negative sign will be ignored.

Motor.ResetCount (ports)
Set the rotation count of one or more motors to 0.

Motor.Schedule (ports, speed, degrees1, degrees2, degrees3, brake)
Move one or more motors with the specified speed values. The speed can be adjusted along the total rotation to get a soft start and a soft stop if needed. The angle to rotate the motor is degrees1+degrees2+degrees3. Any negative signs for the angles will be ignored. At the end of the movement, the motor stops automatically (with or without using the brake). This function returns immediately, so if you want the movement to complete before the program continues you should follow this command with Motor.Wait(ports).

speed  Speed level from -100 (full reverse) to 100 (full forward)

degrees1  The part of the rotation with acceleration

degrees2  The part of the rotation with uniform speed

degrees3  The part of the rotation with deceleration

Motor.SchedulePower (ports, power, degrees1, degrees2, degrees3, brake)
Move one or more motors with the specified power. The power can be adjusted along the total rotation to get a soft start and a soft stop if needed. The angle to rotate the motor is degrees1+degrees2+degrees3. Any negative signs for the angles will be ignored. At the end of the movement, the motor stops automatically (with or without using the brake). This function returns immediately, so if you want the movement to complete before the program continues you should follow this function with Motor.Wait(ports).

power  Power level from -100 (full reverse) to 100 (full forward)

degrees1  The part of the rotation with acceleration

degrees2  The part of the rotation with uniform motion

degrees3  The part of the rotation with deceleration

Motor.ScheduleSync (ports, speed1, speed2, degrees, brake)
Move 2 motors with speeds that can be different through a defined number of degrees. The 'degrees' value is applied to the motor with the higher speed. The two motors are synchronized, which means that when one motor experiences some resistance and can not keep up its speed, the other motor will also slow down or stop altogether. This is especially useful for vehicles with two independently driven wheels which still need to go straight or make a specified turn. This function returns immediately. If you want the movement to complete before the program continues you should use Motor.MoveSync() instead.

ports  Names of exactly 2 motor ports (for example "AB" or "CD")

speed1  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.

speed2  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.

degrees  The angle of the faster motor to rotate. Any negative sign will be ignored.

Motor.Start (ports, speed)
Start one or more motors with the requested speed or set an already running motor to this speed.

speed  Speed value from -100 (full reverse) to 100 (full forward).

Motor.StartPower (ports, power)
Start one or more motors with the requested power or set an already running motor to this power.

power  Power value from -100 (full reverse) to 100 (full forward).

Motor.StartSync (ports, speed1, speed2)
Set two motors to run synchronized at their chosen speed levels. The two motors will be synchronized, that means, when one motor experiences some resistance and can not keep up its speed, the other motor will also slow down or stop altogether. This is especially useful for vehicles with two independently driven wheels which still need to go straight or make a specified turn. The motors will keep running until stopped by another command.

ports  Name of exactly two motor ports (for example "AB" or "CD").

speed1  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the lower port letter.

speed2  Speed value from -100 (full reverse) to 100 (full forward) of the motor with the higher port letter.

Motor.Stop (ports, brake)
Stop one or multiple motors. This will also cancel any scheduled movement for this motor.

Motor.Wait (ports)
Wait until the specified motor(s) has finished a "Schedule..." or "Move..." operation. Using this method is normally better than calling IsBusy() in a tight loop.

    

    

Dig Deeper on Lego Mindstorms:

Lego Mindstorms EV3 extension for Small Basic - EV3 Basic!!!

Program your Lego Mindstorms EV3 Robots with actual Text-Based Coding!

FREE SOFTWARE: Lego Mindstorms EV3 Basic for Small Basic

Lego Mindstorms EV3 Basic - Small Basic is in 20 Languages!!!

Lego Mindstorms - EV3 Basic is the Easiest Installation!!

Lego Mindstorms EV3 Basic - Small Basic teaches you as you type!

Lego Mindstorms EV3 Basic - What are the social collaboration features?

Lego Mindstorms EV3 Basic - Leveraging the Small Basic Graphics Window

Lego Mindstorms EV3 Basic - SPECIAL FEATURES: the Sound & Speaker Objects

Lego Mindstorms Development - Get better handling of Variables!!!

Lego Mindstorms EV3 Basic - Unlock the Power of Text!!!!

Lego Mindstorms EV3 Basic - Built-In Support for I2C Communications and UART

            

Are you a teacher? See DO YOU TEACH LEGO MINDSTORMS? Get free products, training, and support!

 

Have a Small and Basic day!

   - Ninja Ed

Comments