additional guides tetrix getting started · pdf file321 coding sensors guide (robotc®) all...
TRANSCRIPT
![Page 1: Additional Guides TETRIX Getting Started · PDF file321 Coding Sensors Guide (ROBOTC®) All sensors (except the built-in rotation sensor in the motor) connect to Ports 1, 2, 3, or](https://reader031.vdocument.in/reader031/viewer/2022022423/5a9e94bc7f8b9a0d158b8af0/html5/thumbnails/1.jpg)
321
Coding Sensors Guide (ROBOTC®)
Allsensors(exceptthebuilt-inrotationsensorinthemotor)connecttoPorts1,2,3,or4.TheseportsarelocatedonthebottomoftheNXTbrickandpassinformationthroughtheNXTconnectorwires.EnsurethatthewiresconnectingeachsensortotheNXTbrickarepluggedintothecorrectportandthatthishasbeencorrectlysetupintheMotors and Sensors SetupunderRobotintheROBOTC®topmenu.
1.OpentheMotors and Sensors SetupandselecttheSensorstabatthetop.
2.Choosetheportandthetypeofsensorthathasbeenpluggedintothatport.
3.Givethesensoraname.Itisbesttochooseasimplenamethataccuratelyrepresentsthesensorbecausethatisthenamethatwillbeusedthroughoutthecode.
Touch Sensor:ChooseTouchoption.
Light Sensor: ChooseLight ActiveifthereflectedlightvalueisdesiredorLight Inactiveiftheambientlightvalueisdesired.WiththeLightActivesettingtherobotwillproduceitsownlight,andwiththeLightInactivesettingitwillnot.
Sound Sensor: ChoosetheSound DBoptionifthetruedecibelvalueisdesiredortheSound DBAoptionifthedecibelvalueasahumanwouldinterpretitismoreappropriate.
Ultrasonic Sensor: ChoosetheSONARoption.Thevalueofthissensorisreturnedincentimeters.
Note:Thetouchsensorwillprovideadigitalsignal,whiletheotherswillprovideananalogsignal.ThismeansthatthetouchsensorwillonlybeabletosendtwodifferentpiecesofinformationtotheNXTbrick(TrueorFalse,orinthiscase,pressedornotpressed),whiletheothersensorswillsendavaluebetween0and100.ThisisimportanttokeepinmindwhencreatingprogramsthatuseinformationfromthesensorsontheNXTBrick.
TETRIX®GettingStartedGuideAdditionalGuides
![Page 2: Additional Guides TETRIX Getting Started · PDF file321 Coding Sensors Guide (ROBOTC®) All sensors (except the built-in rotation sensor in the motor) connect to Ports 1, 2, 3, or](https://reader031.vdocument.in/reader031/viewer/2022022423/5a9e94bc7f8b9a0d158b8af0/html5/thumbnails/2.jpg)
322
Example 1: Touch Sensor
Thefollowingprogramusesdatafromthetouchsensor.Theprogramwilldriveforwarduntilthetouchsensorispressed.Oncethetouchsensorispressed,therobotwillstopandtheprogramwillend.
taskmain()
{
while(SensorValue(touch)==0)
{
motor[motorD]=70;
motor[motorE]=70;
}
motor[motorD]=0;
motor[motorE]=0;
}
TheWhileLoopallowstherobottocontinuetorununtilthecaseinsidethebracketsisnolongertrue.
Note:Thenumbers0and1taketheplaceofthewords“False”and“True”inthecode,respectively.
TherobotisinaFalsestatewhenthetouchsensor(inthiscase,named“touch”)isnotpressed.ItwillcontinuetorunthecodeinsidetheloopuntiltheconditioninthebracketsisTrue.Inotherwords,thetouchsensormustbe“True”(orpressed)inordertoexittheloop.Therefore,oncethetouchsensorhasbeenpressed,thecodeoutsideoftheWhileLoopwillrun;themotorswillstopandtheprogramwillend.
Example 2: Ultrasonic Sensor
Thefollowingprogramusesdatafromtheultrasonicsensor.Theprogramwilldriveforwarduntilthevaluereads50orless.Oncetheultrasonicsensorreadsavaluethatisinthisrange,therobotwillstopandtheprogramwillend.
taskmain()
{
while(SensorValue(ultrasonic)>50)
{
motor[motorD]=70;
motor[motorE]=70;
}
motor[motorD]=0;
motor[motorE]=0;
}
TheWhileLoopallowstherobottocontinuetorununtilthecaseinsidethebracketsisnolongertrue.Therobot’sultrasonicsensor(inthiscase,named“ultrasonic”)willreturnavaluebetween0and100.ItwillcontinuetocheckthevaluereturnedbythesensorandwillrunthecodeinsidetheWhileLoopuntilthevalueisnolongerabove50.Whenthevaluereads50orless,theWhileLoopwillterminateandthecodeoutsideoftheWhileLoopwillexecute.Therefore,oncethevaluereturnedbytheultrasonicsensorreads50orless,thecodeoutsideoftheWhileLoopwillrun;themotorswillstopandtheprogramwillend.
Coding Sensors Guide (ROBOTC®)
AdditionalGuidesTETRIX®GettingStartedGuide