View unanswered posts | View active topics It is currently Mon Nov 19, 2018 11:18 am






Reply to topic  [ 2 posts ] 
Check if a sensor or motor is connected 
Author Message
Rookie

Joined: Fri Dec 12, 2014 8:55 am
Posts: 8
Post Check if a sensor or motor is connected
Hi,
my Team needs to check (before the start of the sumo match), if all the sensor and motor cables are connected.
It is possible to do this with RobotC.
We use EV3 and NXT.
Regards


Tue Sep 04, 2018 7:55 am
Profile
Rookie

Joined: Thu Sep 25, 2014 8:34 pm
Posts: 23
Post Re: Check if a sensor or motor is connected
Here are two functions. The first is a 'task' which can be started in your main Task using the following:
startTask(portMonitor); // Make sure there is something in every port
As a 'task', the portMonitor function will run continuously while your main task is running. This is a multi-threaded program. In this task, all ports must be connected to something. If a cable gets accidently un-plugged, the robot will sound an alarm notifying the user that something has been unplugged.

The second function checkPort() allows you to pass a port # and a sensor type as parameters and the robot will check to see if that port has the sensor.




Code:
/******************************************************************************************************
  This task monitors the ports to make sure everything is connected
*******************************************************************************************************/
task portMonitor() {
   while(true) {
      if (SensorType(S1)==0 || SensorType(S2)==0 || SensorType(S3)==0 || SensorType(S4)==0) {
         while(SensorType(S1)==0 || SensorType(S2)==0 || SensorType(S3)==0 || SensorType(S4)==0) {
            eraseDisplay();
            setLEDColor(ledRedFlash);
                      displayCenteredBigTextLine(2, "Sensor Port");
                      displayCenteredBigTextLine(4, "#%d is Unused.", (SensorType(S1)==0) ? 1: (SensorType(S2)==0) ? 2: (SensorType(S3)==0) ? 3: 4 );
                      displayCenteredBigTextLine(6, "May be Loose.");
                      displayCenteredBigTextLine(8, "Check Wiring.");
            playTone(440,4); wait1Msec(600);
            playTone(660,4); wait1Msec(600);
         }
         eraseDisplay();
         setLEDColor(ledOff);
      }
      if (motorType(motorA)==0 || motorType(motorB)==0 || motorType(motorC)==0 || motorType(motorD)==0) {
         while(motorType(motorA)==0 || motorType(motorB)==0 || motorType(motorC)==0 || motorType(motorD)==0) {
            eraseDisplay();
            setLEDColor(ledRedFlash);
                      displayCenteredBigTextLine(2, "Motor Port");
                      displayCenteredBigTextLine(4, "#%d is Unused.", (motorType(motorA)==0) ? 1: (motorType(motorB)==0) ? 2: (motorType(motorC)==0) ? 3: 4 );
                      displayCenteredBigTextLine(6, "May be Loose.");
                      displayCenteredBigTextLine(8, "Check Wiring.");
            playTone(440,4); wait1Msec(600);
            playTone(660,4); wait1Msec(600);
         }
         eraseDisplay();
         setLEDColor(ledOff);
      }
   }
}
void checkPort(const tSensors nPort, TSensorTypes tst) {
   if (SensorType(nPort)==0) {
      eraseDisplay();
      setLEDColor(ledRedFlash);

                displayCenteredBigTextLine(2, (tst==sensorEV3_Touch ? "Touch Sensor": (tst==sensorEV3_Color) ? "Color Sensor": (tst==sensorEV3_Ultrasonic) ? "Ultrasonic": ""));
                displayCenteredBigTextLine(4, "In Port 1 Could");
                displayCenteredBigTextLine(6, "be Loose. Check");
                displayCenteredBigTextLine(8, "the Cables");
      playSoundFile("Woops"); wait1Msec(1000);
      OkToMove = true;
   }
 }


Thu Sep 06, 2018 11:18 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.