Code: #pragma config(Sensor, S1, LeftButton, sensorTouch) #pragma config(Sensor, S2, RightButton, sensorTouch) #pragma config(Motor, motorA, TurretControl, tmotorNXT, PIDControl, reversed, encoder) #pragma config(Motor, motorB, RightDrive, tmotorNXT, PIDControl, reversed, encoder) #pragma config(Motor, motorC, LeftDrive, tmotorNXT, PIDControl, reversed, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// Project: Jerry // Function: remote control with two motors acting as joysticks // Author: Mike McFarlane 06-09-12 // Version: 0-1 // Status: dev
task main() { int CurrentRightPower = 1; int CurrentLeftPower = 1; int CurrentTurretPosition = 0; float Gear = 0.5; int Horn = 1;
// reset motor encoders // initial calibration should be done with both joysticks fully forward nMotorEncoder [RightDrive] = 0; nMotorEncoder [LeftDrive] = 0; nMotorEncoder [TurretControl] = 0; wait1Msec(100);
while (true) { // read encoder and print to screen // encoder range; 0 = fully forward, 125 = fully back, 60 = natural neutral CurrentRightPower = nMotorEncoder[RightDrive] + 60; CurrentRightPower *= Gear; CurrentLeftPower = (nMotorEncoder[LeftDrive] + 60) * Gear; CurrentTurretPosition = nMotorEncoder[TurretControl]; nxtDisplayBigTextLine(0, "R: %d", CurrentRightPower); nxtDisplayBigTextLine(2, "L: %d", CurrentLeftPower); nxtDisplayBigTextLine(4, "T: %d", CurrentTurretPosition); // check right button to set motor gear ratio if (SensorValue (RightButton) == 1) { if (Gear == 0.5) {Gear = 1.5;} else {Gear = 0.5;} } while (SensorValue (RightButton) == 1) { // do nothing till button released } nxtDisplayBigTextLine(6, "G: %1.2f", Gear); // check left button for horn - toot toot! if (SensorValue (LeftButton) == 1) { if (Horn == 1) {Horn = 2;} else {Horn = 1;} } while (SensorValue (LeftButton) == 1) { // do nothing till button released } // send message to paired NXT sendMessageWithParm (CurrentRightPower, CurrentLeftPower, Horn); wait1Msec(100); } }
|