Tags:
tag this topic
create new tag
view all tags
<pre>#pragma config(Motor, port2, LeftForward, tmotorServoContinuousRotation, openLoop, reversed) #pragma config(Motor, port3, RightForward, tmotorServoContinuousRotation, openLoop) #pragma config(Motor, port4, LeftBack, tmotorServoContinuousRotation, openLoop, reversed) #pragma config(Motor, port5, RightBack, tmotorServoContinuousRotation, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// </pre> <pre>##function to cause all motors to stop, stopping the vehicle when the button command is pressed void stopMotor() { motor[LeftForward] = 0; motor[RightForward] = 0; motor[LeftBack] = 0; motor[RightBack] = 0; }</pre> <pre> </pre> <pre>##function that causes all wheels to move simultaneously at the same speed, causing it to move forward with a variable passed to it to determine for how long void moveForwardForTime(int howLong) { motor[LeftForward] = 127; motor[RightForward] = 127; motor[LeftBack] = 127; motor[RightBack] = 127; wait1Msec(howLong); ##built in function wait1Msec to receive the howLong variable. This determines how long the vehicle should move forward }</pre> <pre> </pre> <pre>##function that turns left wheels forward at standard forward speed (clockwise), but turns right wheels the negative amount (counter-clockwise). This cause the the vehicle to rotate in place, turning to the right.</pre> <pre>void rotateForTime(int howLong)</pre> <pre>{ motor[LeftForward] = 127; motor[RightForward] = -127; motor[LeftBack] = 127; motor[RightBack] = -127; wait1Msec(howLong); stopMotor(); ##the stopMotor function is used here to ensure that after each iteration used in doSquare the tumbler stops completely before resuming again } </pre> <pre> ##this function calls the moveForwardForTime and rotateForTime functions several times to cause the tumbler to move in a square. They are passed the same variables repeatedly to ensure the movements are uniform, creating the square.</pre> <pre>void doSquare() { moveForwardForTime(2000); rotateForTime(300); moveForwardForTime(2000); rotateForTime(300); moveForwardForTime(2000); rotateForTime(300); moveForwardForTime(2000); rotateForTime(300); return; } </pre> <pre> </pre> <pre>##this function causes the left wheels to move faster than the right wheels, causing the tumbler to form a circle</pre> <pre>void doCircle() { motor[LeftForward] = 127; motor[RightForward] = 20; motor[LeftBack] = 127; motor[RightBack] = 20; wait1Msec(2000); ##no variable is passed in the function definition, so it is instead passed directly to the wait1Msec funstion to determine how long it will rotate } </pre> <pre>##main that assigns doSquare function to 7U, doCircle to 8U, and stopMotor to 7D task main() { while(true) { if(vexRT[Btn7U]) doSquare(); if(vexRT[Btn8U]) doCircle(); if(vexRT[Btn7D]) stopMotor(); } }</pre> <span style="color: #7a4707; font-family: 'Courier New', courier, monaco, monospace; white-space: pre;"><meta name="robots" content="noindex" /></span> -- (c) Fordham University Robotics and Computer Vision
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2013-03-25
-
DavidWalsh
Home
Site map
Main web
Sandbox web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback