VCS Example Program - Modkit - V5 Clawbot - Opening and Closing the Claw

Get more with VEXcode
We recommend you transition to our new software. VEXcode has both block-based and text-based options, that work on Chromebooks, iPads, Android tablets, Windows and Macs. Visit code.vex.com for more details on how to download VEXcode.
VEX Coding studio has been discontinued and is no longer available for download. Already downloaded? The program will continue to function but will no longer be supported.
Users who transition to VEXcode can migrate their C++/C++ Pro projects to VEXcode Text by following this article.

This example program shows how to program the V5 Clawbot to open and close its claw using Modkit.

BasicOpenCloseClaw.vex

Configuration
  • A V5 Smart Motor, on Port 3, named ClawMotor.
Program

How it works

First, the when (STARTED) block tells the robot to run this code when the program starts.

Then, the claw motor is set to spin in reverse. Since spin is used, the motor will begin rotating and the program will continue immediately. Spinning in reverse causes the claw motor to open the claw jaws.

Then the program will pause for two-tenths of a second ( .2 seconds) to allow the motor to start spinning.

Next, the program will enter a while loop, continuously checking if the motor's velocity is negative (< 0). When the claw jaws open fully, the motor's movement will be resisted. When this occurs, the velocity will become 0 and the loop will exit. Because the loop is empty, nothing else will happen while the claw is opening.

Then, when the claw has finished opening, the claw motor will be commanded to stop. This stops the motor's spin so it does not continue trying to open. When this happens, the claw jaws will spring back slightly.

Next, the program will pause for 1 second.

Finally, the spin block, while loop, and stop block are repeated, but spinning forward. Spinning the claw motor in the opposite direction will make the claw jaws close. When the claw's motion is resisted, the loop will finish and the motor will stop.