Legacy EDR for Beginners

I’m new to the VEX world. I’m also new to the FIRST FTC world. I consider myself a “Mentor In Training”. Our school has just restarted an FTC program and were gifted about 20 Vex Claw Bots by a dept. in the school that is discontinuing their Vex Robotics classes. I am not a programmer, but I am a retire d Mainframe repair tech and Network Infrastructure Tech. I think I have all the pieces needed to get some students started coding the robots, except the orignal sample code described in the documentation. We have the Robot C software up and running on Windows 11 and the hardware appears to be working (if I can believe the lights). Does anyone have a copy of the original C code for the Claw Bot I can use as a starting point for testing hardware and as a seed for our beginning programmers.

Thank you in advance for any time/effort you may put into this request.
Larry

1 Like

I assume these are cortex brains and not the even older pic systems.

The “default” code provided by VEX can be downloaded by the old cortex firmware utility, however, RobotC includes as a sample program that is a close approximation of that default code. here it is if you cannot find it.

ROBOTC VEX Cortex Default.c
#pragma config(Sensor, in1,    ana1,                sensorPotentiometer)
#pragma config(Sensor, in2,    ana2,                sensorPotentiometer)
#pragma config(Sensor, in3,    ana3,                sensorPotentiometer)
#pragma config(Sensor, in4,    ana4,                sensorPotentiometer)
#pragma config(Sensor, in5,    ana5,                sensorPotentiometer)
#pragma config(Sensor, in6,    ana6,                sensorPotentiometer)
#pragma config(Sensor, in7,    ana7,                sensorPotentiometer)
#pragma config(Sensor, in8,    ana8,                sensorPotentiometer)
#pragma config(Sensor, dgtl1,  jmp1,                sensorTouch)
#pragma config(Sensor, dgtl2,  jmp2,                sensorTouch)
#pragma config(Sensor, dgtl3,  jmp3,                sensorTouch)
#pragma config(Sensor, dgtl4,  jmp4,                sensorTouch)
#pragma config(Sensor, dgtl5,  jmp5,                sensorTouch)
#pragma config(Sensor, dgtl6,  jmp6,                sensorTouch)
#pragma config(Sensor, dgtl7,  jmp7,                sensorTouch)
#pragma config(Sensor, dgtl8,  jmp8,                sensorTouch)
#pragma config(Sensor, dgtl9,  jmp9,                sensorTouch)
#pragma config(Sensor, dgtl10, jmp10,               sensorTouch)
#pragma config(Sensor, dgtl11, jmp11,               sensorTouch)
#pragma config(Sensor, dgtl12, jmp12,               sensorTouch)
#pragma config(Motor,  port1,           LeftDrive1,    tmotorNormal, openLoop)
#pragma config(Motor,  port2,           LeftDrive2,    tmotorNormal, openLoop)
#pragma config(Motor,  port3,           LeftDrive3,    tmotorNormal, openLoop)
#pragma config(Motor,  port4,           RightDrive4,   tmotorNormal, openLoop)
#pragma config(Motor,  port5,           RightDrive5,   tmotorNormal, openLoop)
#pragma config(Motor,  port6,           Mech1,         tmotorNormal, openLoop)
#pragma config(Motor,  port7,           Mech2,         tmotorNormal, openLoop)
#pragma config(Motor,  port8,           Mech3,         tmotorNormal, openLoop)
#pragma config(Motor,  port9,           Mech4,         tmotorNormal, openLoop)
#pragma config(Motor,  port10,          RightDrive10,  tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// Motors by default: + CW, - CCW
// Jumper IN  = 1 (touch)
// Jumper OUT = 0 (touch)
// Analog NOT PRESSED = 249; (touch as potentiometer; values are +-1)
// Analog PRESSED     = 5; (touch as potentiometer; values are +-1)

/*
jmp1  = 0: motor 1 flipped
jmp2  = 0: motor 2 flipped
jmp3  = 0: motor 3 flipped
jmp4  = 0: motor 4 flipped
jmp5  = 0: motor 5 flipped
jmp6  = 0: motor 6 flipped
jmp7  = 0: motor 7 flipped
jmp8  = 0: motor 8 flipped
jmp9  = 0: motor 9 flipped
jmp10 = 0: motor 10 flipped

jmp11 = 0 && jmp12 = 0: Single Driver TANK
jmp11 = 1 && jmp12 = 0: Dual Driver   TANK
jmp11 = 0 && jmp12 = 1: Single Driver ARCADE
jmp11 = 1 && jmp12 = 1: Dual Driver   ARCADE

ana1  < 200: motor 6 IGNORE CCW
ana2  < 200: motor 6 IGNORE CW
ana3  < 200: motor 7 IGNORE CCW
ana4  < 200: motor 7 IGNORE CW
ana5  < 200: motor 8 IGNORE CCW
ana6  < 200: motor 8 IGNORE CW
ana7  < 200: motor 9 IGNORE CCW
ana8  < 200: motor 9 IGNORE CW
*/


task main()
{
  int ana_1 = 0;
  int ana_2 = 0;
  int ana_3 = 0;
  int ana_4 = 0;
  int ana_5 = 0;
  int ana_6 = 0;
  int ana_7 = 0;
  int ana_8 = 0;

  while(true)
  {
    //GLOBAL CHANGES & CHECKS:
    bMotorReflected[LeftDrive1]   = (bool)SensorValue[jmp1];
    bMotorReflected[LeftDrive2]   = (bool)SensorValue[jmp2];
    bMotorReflected[LeftDrive3]   = (bool)SensorValue[jmp3];
    bMotorReflected[RightDrive4]  = (bool)SensorValue[jmp4];
    bMotorReflected[RightDrive5]  = (bool)SensorValue[jmp5];
    bMotorReflected[Mech1]        = (bool)SensorValue[jmp6];
    bMotorReflected[Mech2]        = (bool)SensorValue[jmp7];
    bMotorReflected[Mech3]        = (bool)SensorValue[jmp8];
    bMotorReflected[Mech4]        = (bool)SensorValue[jmp9];
    bMotorReflected[RightDrive10] = (bool)SensorValue[jmp10];

    if(SensorValue[ana1] < 200)
      ana_1 = 0;
    else
      ana_1 = 1;

    if(SensorValue[ana2] < 200)
      ana_2 = 0;
    else
      ana_2 = 1;

    if(SensorValue[ana3] < 200)
      ana_3 = 0;
    else
      ana_3 = 1;

    if(SensorValue[ana4] < 200)
      ana_4 = 0;
    else
      ana_4 = 1;

    if(SensorValue[jmp11] == 0 && SensorValue[jmp12] == 0)      // if !jmp11 && !jmp12:----------------| SINGLE DRIVER - TANK |----------------------------------------
    {
      if(SensorValue[ana5] < 200)
        ana_5 = 0;
      else
        ana_5 = 1;

      if(SensorValue[ana6] < 200)
        ana_6 = 0;
      else
        ana_6 = 1;

      if(SensorValue[ana7] < 200)
        ana_7 = 0;
      else
        ana_7 = 1;

      if(SensorValue[ana8] < 200)
        ana_8 = 0;
      else
        ana_8 = 1;

      motor[LeftDrive1]   = vexRT[Ch3];       // up = CW
      motor[LeftDrive2]   = vexRT[Ch3];       // up = CW
      motor[LeftDrive3]   = vexRT[Ch3];       // up = CW
      motor[RightDrive4]  = -vexRT[Ch2];      // up = CCW
      motor[RightDrive5]  = -vexRT[Ch2];      // up = CCW
      motor[Mech1]        = ((vexRT[Btn5U] * 127) * ana_2) - ((vexRT[Btn5D] * 127) * ana_1);   // U = CW, D = CCW
      motor[Mech2]        = ((vexRT[Btn6U] * 127) * ana_4) - ((vexRT[Btn6D] * 127) * ana_3);   // U = CW, D = CCW
      motor[Mech3]        = ((vexRT[Btn7U] * 127) * ana_6) - ((vexRT[Btn7D] * 127) * ana_5);   // U = CW, D = CCW
      motor[Mech4]        = ((vexRT[Btn8U] * 127) * ana_8) - ((vexRT[Btn8D] * 127) * ana_7);   // U = CW, D = CCW
      motor[RightDrive10] = -vexRT[Ch2];        // up = CCW
    }
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------------
    // if jmp11 && !jmp12:----------------------| DUAL DRIVER - TANK |-----------------------------------------------------------------------------------------------------
    else if(SensorValue[jmp11] == 1 && SensorValue[jmp12] == 0)
    {
      motor[LeftDrive1]   = vexRT[Ch3];       // up = CW
      motor[LeftDrive2]   = vexRT[Ch3];       // up = CW
      motor[LeftDrive3]   = vexRT[Ch3];       // up = CW
      motor[RightDrive4]  = -vexRT[Ch2];      // up = CCW
      motor[RightDrive5]  = -vexRT[Ch2];      // up = CCW
      motor[Mech1]        = ((vexRT[Btn5UXmtr2] * 127) * ana_2) - ((vexRT[Btn5DXmtr2] * 127) * ana_1);   // U = CW, D = CCW
      motor[Mech2]        = ((vexRT[Btn6UXmtr2] * 127) * ana_4) - ((vexRT[Btn6DXmtr2] * 127) * ana_3);   // U = CW, D = CCW

      if((SensorValue[ana_6] < 200 && vexRT[Ch3Xmtr2] > 0) || (SensorValue[ana_5] < 200 && vexRT[Ch3Xmtr2] < 0))
      {
        motor[Mech3]        = 0;
      }
      else
      {
        motor[Mech3]        = vexRT[Ch3Xmtr2];  // up = CW
      }

      if((SensorValue[ana_8] < 200 && vexRT[Ch2Xmtr2] > 0) || (SensorValue[ana_7] < 200 && vexRT[Ch2Xmtr2] < 0))
      {
        motor[Mech4]        = 0;
      }
      else
      {
        motor[Mech4]        = (vexRT[Ch2Xmtr2]);  // up = CW
      }

      motor[RightDrive10] = -vexRT[Ch2];        // up = CCW
    }
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    else if(SensorValue[jmp11] == 0 && SensorValue[jmp12] == 1)    // if !jmp11 && jmp12:---------------------| SINGLE DRIVER - ARCADE |-------------------------------------
    {
      motor[LeftDrive1]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[LeftDrive2]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[LeftDrive3]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[RightDrive4]  = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
      motor[RightDrive5]  = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
      motor[Mech1]        = ((vexRT[Btn5U] * 127) * ana_2) - ((vexRT[Btn5D] * 127) * ana_1);   // U = CW, D = CCW
      motor[Mech2]        = ((vexRT[Btn6U] * 127) * ana_4) - ((vexRT[Btn6D] * 127) * ana_3);   // U = CW, D = CCW

      if((SensorValue[ana_6] < 200 && vexRT[Ch3] > 0) || (SensorValue[ana_5] < 200 && vexRT[Ch3] < 0))
      {
        motor[Mech3]        = 0;
      }
      else
      {
        motor[Mech3]        = vexRT[Ch3];  // up = CW
      }

      if((SensorValue[ana_8] < 200 && (-vexRT[Ch4]) > 0) || (SensorValue[ana_7] < 200 && (-vexRT[Ch4]) < 0))
      {
        motor[Mech4]        = 0;
      }
      else
      {
        motor[Mech4]        = (-vexRT[Ch4]);  // right = CCW
      }
      motor[RightDrive10] = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
    }
    //---------------------------------------------------------------------------------------------------------------------------------------------------------------------
    else if(SensorValue[jmp11] == 1 && SensorValue[jmp12] == 1)    // if jmp11 && jmp12:---------------------| DUAL DRIVER - ARCADE |--------------------------------------
    {
      motor[LeftDrive1]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[LeftDrive2]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[LeftDrive3]   = vexRT[Ch1] + vexRT[Ch2];       // up = CW, right = CW
      motor[RightDrive4]  = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
      motor[RightDrive5]  = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
      motor[Mech1]        = ((vexRT[Btn5UXmtr2] * 127) * ana_2) - ((vexRT[Btn5DXmtr2] * 127) * ana_1);   // U = CW, D = CCW
      motor[Mech2]        = ((vexRT[Btn6UXmtr2] * 127) * ana_4) - ((vexRT[Btn6DXmtr2] * 127) * ana_3);   // U = CW, D = CCW

      if((SensorValue[ana_6] < 200 && vexRT[Ch3Xmtr2] > 0) || (SensorValue[ana_5] < 200 && vexRT[Ch3Xmtr2] < 0))
      {
        motor[Mech3]        = 0;
      }
      else
      {
        motor[Mech3]        = vexRT[Ch3Xmtr2];  // up = CW
      }

      if((SensorValue[ana_8] < 200 && vexRT[Ch2Xmtr2] > 0) || (SensorValue[ana_7] < 200 && vexRT[Ch2Xmtr2] < 0))
      {
        motor[Mech4]        = 0;
      }
      else
      {
        motor[Mech4]        = (vexRT[Ch2Xmtr2]);  // up = CW
      }

      motor[RightDrive10] = vexRT[Ch1] - vexRT[Ch2];       // up = CW, right = CCW
    }
    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  }
}

2 Likes

That is correct. I have the Robot C installed but I have no idea where it may have stored teh Sample Code. Now,… How do i download what you posted from this site?

FYI,

I just did a cut and paste via the copy icon in the upper right corner, into notepad and save as Defualt.C

That seems to work

Thank you SOOOOO much for the prompt response. I’m hoping to have 5 robots the students built running a day or two after the Holiday Break.

To be honest that code is somewhat more complex than you really needed, it was a simulation of the VEX provided default code and as such also handled the various options that could be set using jumpers. If all you need is to drive the clawbots then it can be significantly simplified.

Sample programs are accessed via the File menu (open sample program) and should take you to the VEX2 folder if the cortex is selected as the platform. That default code is in the advanced folder.

2 Likes

Thank you again. I spent the last two hours restoring my machine. I accidentally set KIOSK Mode and had no idea how to turn it off again. I found some more samples as well as what I’ll call templates for different drive trains.

Hopefully I’ll be able to compile and load a program before we start back up. I had the code you shared compiled, but I couldn’t load it to the controller. I kept getting error messages about secondary controller could not be verified.

I’m just about to set it aside for the day.


This is the actual error I am seeing.

Headed to bed. Need sleep.

Thank you again for your efforts.

Larry

Did you load the RobotC virtual machine onto the cortex ? You need to do that before you can download and run a usrr program.

1 Like

This is the first I’ve seen it is even a thing. I did see in the complier settings an option to deploy to a VM, but I didn’t/don’t have a clue where to find a VM for the Cortex. Do you have a link you could share. I have found several dead links while trying to pull the legacy pieces together, but nothing for the VM (directly).

Make sure cortex 2.0 is selected as the platform

Manually load the RobotC VM.

There are some tutorials still around on youtube and other places if you search, but remember that at this point RobotC is essentially an unsupported piece of software.

2 Likes

Thank you again. I found some “Step by Step” help on the RobotC.net web site with links to some YouTube videos. This should keep me busy over the Holiday Break.

I’m making progress. I’m also probably as impatient as the 6th graders I’m mentoring.

I attached a pair of 393 2 wire motors to ports 1 and 10, loaded the Basic Motion - Forward sample and compiled. The motors ran YAEH.

So I attempted to get an ultrasonic range module to DIO ports 9 and 10, with the cable labeled Input to port 10. This was done as per the online info saying to use consecutive DIO ports with the controller.

I loaded the sample code for smooth ultrasonic sensor and used the Robot C sensor setup tool to configure for DIO port 9 and 10. And I also used it to setup the left and right drive motors on 1 and 10.

The motors work great, the sensor not so much. Should I try swapping the input and output leads to see what happens? I don’t want to smoke test the sonar. It appears to be the same as my SR04 I use on my Arduino based robots just kid proofed with the Vex Dupont shells.

Just swap them and see if it works. Never heard of any damage happening. I can usually hear the ultrasonic clicking if it’s working but not everyone can.

1 Like

I can normally hear them clicking as well. And so does my cat. She freaks every time I crank one up.

Swapping does nothing. I’ve also tried a couple of different ports as well.

Time to set it aside again. I have to hide my hammer. (<:

I was able to :
a) Load the ClawBot Sample Code
b)Compile the ClawBot Sample Code
c)Deploy the ClawBot Sample Code
d)Run the motors wirelessly via the VexNet Game Controller

I am still not able to get the UltraSonic Range Sensor to do anything.

I’m going to find a way to test the DIO ports. Possibly with an LED. I just need to figure out if I need a Current Limiting Resister or not. Time to do another Internet search.

Thank you again for all your time and help.
Larry

Any chance you can share your code and a few picture of how you have everything connected? I’d also recommend giving port 7 and 8 a shot instead of 9 and 10. I remember that there was some weirdness stemming from ports 4 and 10 sharing an interrupt though I’m not sure if that’s relevant here.

The code is the Sample code for the Ultrasonic. I’ve tried all the samples.

I’ve tried ports 1 through 10 with the input on the low number and the high number. No clicks, That’s why i wanted to test the DIO ports output to be sure the Cortex I’m using hasn’t been previously fried.

I am using the “Sensor-Motor” config tool in Robot-C to change the ports.

There was a weird PIC interrupt issue about shared ports. Maybe James brought it forward to the Cortex to keep it Legacy compatible. :roll_eyes:

But yes @e415ldc please post your code, the sonar was always a pain to work with.

Here is the code. I used the Sample Bad Sonar since it had less to comment out. I don’t have an LCD screen so I commented out all references to LCD to “hopefully” reduce any issues not having one might cause.

#pragma config(Sensor, dgtl1,  sonarSensor,    sensorSONAR_cm)
#pragma config(Motor,  port1,           leftMotor,     tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port10,          rightMotor,    tmotorVex393_HBridge, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*----------------------------------------------------------------------------------------------------*\
|*                                     - VEX Bad Sonar Tracking -                                     *|
|*                                      ROBOTC on VEX 2.0 Cortex                                      *|
|*                                                                                                    *|
|*  Not only is this code a poor example of controling your robot with sonar (it is too jerky and     *|
|*  will probably shake your robot apart!) but it is also written in very poor style.  Avoid making   *|
|*  your programs small and confusing.  Take time to expand your program, try to only do one 'thing'  *|
|*  per line.                                                                                         *|
|*                                                                                                    *|
|*                                        ROBOT CONFIGURATION                                         *|
|*    NOTES:                                                                                          *|
|*    1)  The Sonar Sensor should be somewhere on the FRONT of the robot, facing FORWARD.             *|
|*                                                                                                    *|
|*    MOTORS & SENSORS:                                                                               *|
|*    [I/O Port]              [Name]              [Type]              [Description]                   *|
|*    Digital 5               sonarSensor         VEX Sonar Sensor    Front mounted, front facing     *|
|*    Motor - Port 2          leftMotor           VEX Motor           Left motor                      *|
|*    Motor - Port 3          rightMotor          VEX Motor           Right motor                     *|
\*-----------------------------------------------------------------------------------------------4246-*/


//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main(){
  int speed;            // Will hold a speed for the motors.

  for(;;){              // 'for ever' (an empty for loop--clever, but ugly)

    // (if you only have on line of code below each 'if' and 'else', you don't need braces '{}' -- again, poor style)

    if(SensorValue(sonarSensor) > 20 || SensorValue(sonarSensor) < 0)         // '> 20 || < 0' tells the robot to go forward while the Sonar Sensor reads in data greater than 20cm away.
      motor[leftMotor] = motor[rightMotor] = speed = 127;                     // Read from Right to Left: '127 is assigned to 'speed' is assigned to 'rightMotor' is assigned to 'leftMotor'.'
    else if(SensorValue(sonarSensor) < 20 && SensorValue(sonarSensor) > 0)    // '< 20 && > 0' tells the robot to go backward while the Sonar Sensor reads in data less than 20 cm away.
      motor[leftMotor] = motor[rightMotor] = speed = -127;                    // Back up FULL SPEED! (to avoid collision #_# )
    else                                                                      // The object is EXACTLY 20cm away.
      motor[leftMotor] = motor[rightMotor] = speed = 0;                       // STOP! Goal reached!

//    clearLCDLine(0);                                  /* Display the    */
//    displayLCDPos(0,0);                               /* reading of the */
//    displayNextLCDString("Sonar: ");                  /* Sonar Sensor   */
//    displayNextLCDNumber(SensorValue(sonarSensor));   /* on line 0.     */

//    clearLCDLine(1);                                  /* Display the    */
//    displayLCDPos(1,0);                               /* current speed  */
//    displayNextLCDString("Speed: ");                  /* of the motors  */
//    displayNextLCDNumber(speed);                      /* on line 1.     */

    wait1Msec(100);                                   // Take 10 readings per second.
  }
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

edit: code tags added by. moderators, please remember to use them.