#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 !!*// /* Project 1-3 U P A N D B A C K Using Synched Motors Ron Kessler Created 8/9/2018 Updated 8/11/2018 8-11-18 Made Motor B master because it was slower motor. Drives way straighter!!! PURPOSE: Shows how to make motors go really straight! Even with PID control, my bot drifted. I will introduce Synchronized motors to fix that! Note:If your bots front and rear axles are not aligned (like mine), nothing will make it go straight! Testing showed my left motor always went faster and the right one could not keep up. So I made B(slow motor) the master and it worked quite well! You use sync motors to make sharp clean turns also. */ task main() { nSyncedMotors = synchBC; //you have choices here. I made motor B the master and C the slave. //whatever motor B does, C will copy it. //---now make motor C run the same speed as B so the bot moves straight nSyncedTurnRatio = 100; //ratio means 1:1 when value is 100. // use nSyncedMotors = synchNone; to unsynch them! //---always reset the motor controllers first using the nMotorEncoder command. nMotorEncoder[rightMotor] = 0; //---set the RIGHT encoder target property to 1800 degrees. nMotorEncoderTarget[rightMotor] = 1800; //---now run motor B forward at 35% motor[rightMotor] = 35; //only need to command RIGHT motor since they are synched wait1Msec(10000); //******************************************** //---now make it back up //---reset the motor encoder again. ONLY THE RIGHT ONE nMotorEncoder[rightMotor] = 0; //---set the RIGHT encoder target property to 1800 degrees again. Setting it to a negative number // will make the motor coast to a stop after reaching the target distance. nMotorEncoderTarget[rightMotor] = 1800; //---now run motor backwards at 35% motor[rightMotor] = -35; wait1Msec(10000); }