#pragma config(Motor, motorA, , tmotorNXT, openLoop) #pragma config(Motor, motorB, rightMotor, tmotorNXT, PIDControl, encoder) #pragma config(Motor, motorC, leftMotor, tmotorNXT, PIDControl, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// /* U P A N D B A C K Ron Kessler Created 8/8/2018 Updated 8/10/2018 PURPOSE: Shows how to make motors go Straight for a specific distance and also use "speed control" to maintain correct speed up/down hills. We will also name our motors to make code easier to manage. The motors have rotation sensors that tell how far it has moved. We will use that feature to make the bot move an exact distance. STEP 1: Select Robot | Motors and Sensors Setup In the motors dialog set up motors for our bots Set motor A to none Set motor b to "rightMotor" Set motor c to "leftMotor" Make sure PID is checked Now, you will see compiler directives added to the top of our code. If the motors are backwards on your bot, then check "reversed". */ task main() { //---always reset the motor controllers first using the nMotorEncoder command. nMotorEncoder[leftMotor] = 0; nMotorEncoder[rightMotor] = 0; //---now set how far to make the wheels rotate. This is always in degrees of rotation. // So let's say we want it to go 5 rotations, then distance will be 5 * 360 = 1800 //---set the encoder target property to 1800 degrees. nMotorEncoderTarget[leftMotor] = 1800; nMotorEncoderTarget[rightMotor] = 1800; //---now run motors forward at 35% motor[leftMotor] = 35; motor[rightMotor] = 35; wait1Msec(10000); //10 seconds to give motors a chance to complete 5 rotations //******************************************** //---now make it back up //---reset the motor encoder again. nMotorEncoder[leftMotor] = 0; nMotorEncoder[rightMotor] = 0; //---set the encoder target property to 1800 degrees again. nMotorEncoderTarget[leftMotor] = 1800; nMotorEncoderTarget[rightMotor] = 1800; //---now run motors backwards at 35% motor[leftMotor] = -35; motor[rightMotor] = -35; wait1Msec(10000); //10 seconds to get back to where it started } //Now do Challenge 1.1 Dead Recockoning