Basic Programming request

Hey all,

With our programmer on holiday and apparently no way of contacting him, we’re stuck with a half built robot that we don’t want to finish untill we can test the lift/hang.

Would it be possible for anyone to post a basic programming template we can just plug in.

We’re trying out a two wheel drive robot with the +60% speed HS motors, two motors for lift, one so far for hang and two for intake if that’s helpful for anyone. We have a cortex microcontroller but i’m not sure if we have a working robot C.

But any help would be greatly appreciated.

Can you post a picture of your robot along with what ports the motors are plugged into and a description of what buttons you want to control the motors?

Yea sure, if you post the details I could probably get it done withing 24 - 48 hours depending on work load.

I would be glad to help, let us know the motor ports, and what you want each joystick/button to control.

~Jordan

Wow, thank you all for offering to help.

The current ports are

1 - Drive 1 (Speed gearing on a HS motor)
2 - Drive 2 (Speed gearing on a HS motor)
3 - Lift 1
4 - Lift 2
10 - Hang 1

For the buttons could it be right stick for arcade drive, left stick for lift, 5U/D for hang.

Thanks again.

I don’t know how your motors are set up, so you may have to reverse them.

#pragma config(Motor,  port1,           leftWheel,     tmotorNormal, openLoop)
#pragma config(Motor,  port2,           rightWheel,    tmotorNormal, openLoop)
#pragma config(Motor,  port3,           lift1,         tmotorNormal, openLoop)
#pragma config(Motor,  port4,           lift2,         tmotorServoStandard, openLoop)
#pragma config(Motor,  port10,          hang,          tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main(){
  while(true){
    motor[rightWheel] = vexRT[Ch2] - vexRT[Ch1];
    motor[leftWheel] = vexRT[Ch1] - vexRT[Ch2];
    motor[lift1] = vexRT[Ch3];
    motor[lift2] = vexRT[Ch3];
    motor[hang] = vexRT[Btn5U] ? 127 : vexRT[Btn5D] ? -127 : 0;
  }
}

Thanks heaps for that, the problem I have now is getting the program to work

I’ve

  • installed the master firmware on micro/joystick
  • install joystick and robotC firmware
  • plugged in the micro to laptop using USB A-A chord.
  • clicked Compile and Download (which worked)
  • restarted the micro, plugged the keys in and hoped something would work. Which it didn’t

What did I do wrong or did I miss something?

Iv created some code that works with my framework, just download the framework here: https://vexforum.com/local_links.php?catid=26&linkid=199
then go into the folders and find the file called “IT.c” then open it in RobotC and replace ALL the code with this code (Note: you might need to reverse the motor ports, just look for the corresponding port number and change it from 0 to 1):


#pragma config(ProgramType, Competition)
#pragma defaultFile
#pragma platform(VEX, VEX2)

// ~~~~~~~~~~~~~~~~~~~
// ~~~~^^^^^^^^^^^~~~~
// ~~~~DO NOT EDIT~~~~
// ~~~~~~~~~~~~~~~~~~~

// MAIN PROGRAM DESCRIPTIONS
// -------------------------
// This new Version of IT is designed to be co-compatible with both Vex 0.5 and Vex Cortex (2.0)
// micro-controllers. All the loading is done automatically when you choose which platform you want in the menu.
// All you need to do is click "Open and Compile" and it loads all the correct elements into RobotC.
// Use CORES to make your programming better and add more functionality to your robot by accessing firmware directly.

// PROGRAM NOTES
// -------------
// NOTE: If you find a bug or want an extra CORES feature added, please send an email to: charsleysa@gmail.com
// NOTE: CORES is an acronym for "Central Operating Redundant Execution System"

// PROGRAM WARNINGS
// ----------------
// WARNING: DO NOT COMPILE FILES BY THEMSELVES, COMPILE THIS ROOT FILE!!!
// WARNING: LEAVE THE CORES INCLUDES IN THE SAME ORDER!!!
// WARNING: CORES CODE IS VITAL TO RUN, DO NOT CHANGE IT UNLESS YOU KNOW WHAT YOUR DOING!!!

// PROGRAM VERSION
// ---------------
// Version: 2.0 ReAmped RC

// Comment this out for Fun Mode
#define COMP

// A varible that the main task uses
bool bIsAI = false;

// Main Task
task IT();
task UpdateCORES();
void preSetup();
void Auto();
void Driver();
task Parallel();

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~
// ~~~~ INCLUDES  ~~~~
// ~~~~~~~~~~~~~~~~~~~

// --->>
// These files first in the order!!!

// Pre Definitions for CORES
#include "PreDefinitions.cpp"

// Maths Extensions for CORES
#include "MathExtension.cpp"

// Control Setup for CORES
#include "ControlHandler.cpp"

// Motor Setup for CORES
#include "Motors.cpp"

// Sensor Setup for CORES
#include "Sensors.cpp"

// Drive Functions for CORES
#include "Drive.cpp"

// Inlcudes for Fun Mode / Competition
#ifndef COMP

// FunMode File
#include "FunMode.cpp"

#elif defined(COMP)

// Competition Template - RECOMMENDED!!!
#include "Competition.cpp"

#endif

// <<---

// XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
// ALL PLUGIN'S SHOULD BE INCLUDED UNDERNEATH THIS LINE, CORES FILES ARE PLACED ABOVE!!!

// Optional Class Extensions
//#include "ClassExtension.cpp"

// Optional Camera Functions
//#include "Camera.cpp"

// Optional Pneumatic Functions
//#include "Pneumatics.cpp"

// Optional Double Claw Funtions
//#include "TwoProng.cpp"

// Optional Power Level Indicator
//#include "PowerIndicator.cpp"

// The include for the UAV Project
//#include "UAV.cpp"

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~~
// ~~~~ CORES CODE ~~~~
// ~~~~~~~~~~~~~~~~~~~~

// Anything that needs to updated 24/7 can be done separately
// so if the this task jams then the main program can continue.
// If this task jams then it can be overriden to stop crashing.
task UpdateCORES()
{
  while(true)
  {
    UpdateControllers();
    UpdateSensors();
    UpdateMotors();
  }
}

// DO NOT INSERT YOUR CODE HERE ANYMORE!!!
task IT()
{
  StartTask(UpdateCORES);
  StartTask(Parallel);

  // ATTENTION: This is for the UAV project, delete if needed!!!
  // ATTENTION: This segment of code will be commented on the release code!!!
  //StartTask(UAV);

  while(true)
  {
    if (bIsAI == false){ Driver(); }
    else if (bIsAI == true){ Auto(); }
  }
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ~~~~~~~~~~~~~~~~~~~
// ~~~~ MAIN CODE ~~~~
// ~~~~~~~~~~~~~~~~~~~

// You should define all your functions beforehand!

void CustomDrive();
void Extra();

// Put all your custom pre-setup code HERE!!!
void preSetup()
{
  // These are just some controller setups, if not set then they will revert to 0
  Controller.Override = false;
  Controller.Trim = 20;
}

// Put all your custom autonomous code HERE!!!
void Auto()
{
  // Turn on controller simulation
  Controller.Override = true;
  
  // Now drive forward for 2 seconds
  Controller.Ch2 = 127;
  wait1Msec(2000);
  Controller.Ch2 = 0;
  
  // Now rotate the bot for 1 second
  Controller.Ch1 = 127;
  wait1Msec(1000);
  Controller.Ch1 = 0;
  
  // Now turn off controller simulation
  Controller.Override = false;
}

// Put all your custom driver code HERE!!!
void Driver()
{
}

// Put all your custom code that you want to run in parallel HERE!!!
// Note: remember for you code to continue running, you must have the while loop.
task Parallel()
{
  while (true)
  {
    CustomDrive();
    Extra();
  }
}

void CustomDrive()
{
  // This flips the motors accordingly so they can be used altogether.
  bMotorFlippedMode[port1] = 0;
  bMotorFlippedMode[port2] = 0;

  // This sets the motors according to the X and Y of the right joystick.
  int SideA = 0;
  int SideB = 0;
  SideA = Controller.Ch2 - Controller.Ch1;
  SideB = Controller.Ch2 + Controller.Ch1;

  // Now clamps those values so that they dont go under -127 or over 127.
  SideA = Math_Clamp(SideA, -127, 127);
  SideB = Math_Clamp(SideB, -127, 127);

  Motors.mtr1 = SideA;
  Motors.mtr2 = SideA;
}

void Extra()
{
  // For the lift
  bMotorFlippedMode[port3] = 0;
  bMotorFlippedMode[port4] = 0;
  
  // For the hang
  bMotorFlippedMode[port10] = 0;
  
  Motors.mtr3 = Controller.Ch3;
  Motors.mtr4 = Controller.Ch3;
  
  if (Controller.Btn5U)
  {
    Motors.mtr10 = 100;
  }
  else if (Controller.Btn5D)
  {
    Motors.mtr10 = -100;
  }
  else
  {
    Motors.mtr10 = 0;
  }
}

P.S: It also has an example autonomous there if you want to see how to create a simple autonomous, if you dont want it then you can just delete all the code inside the Auto() function.

Hope this helps!

Did you link your controller and cortex together? Plug in a USB cable into the cortex and link it to the controller. Then turn the cortex on. When the orange lights stop flashing and the green lights come on, it should work. If not, then your problem is something else.

EDIT: I have the robot working now, sort of. Ii’m using the usb cable as the keys dont seem to work. But the robot only works for around 30-40 seconds than it stop responding.

Thanks for at least getting it moving though. I’ve flipped one of the motors so the lift works now but when I try and download it to the robot it says there is no communications link available even though the usb is plugged in the pc and micro. Also, how do I get it to turn? It can only go straight.

Where in the code do I update it so I can get the intake working? The motors are plugged into A and B in the power expander to ports 6 and 7.

Who’s code are you using?

charsleysa’s, I never got your code working but I think i’ll have another go now.

I will be doing some intensive debugging of code in theory, because I do not have a cortex, only the PIC, to add intake just put it in the Extra() function down the bottom

This is an unknown error, could you please send me info on whats happening and what you did when it cut out, because if its an error with the code I need to fix it ASAP!

Sorry for this, it was an error in my coding, you need to change this in the CustomDrive() function:


  Motors.mtr1 = SideA;
  Motors.mtr2 = SideA;

to


  Motors.mtr1 = SideA;
  Motors.mtr2 = SideB;

This can be added in the Extra() function.

Please send me an update of your code to charsleysa@gmail.com if you need me to add in extra features. or you can direct message me, please note that there will be updates to the framework soon so you will need to backup the main file you are working on then update and overwrite the main file with your code, Im working on making updates more smoothly.

Can I manually change the ports from the ones in your program to the ones I have now?

The ports are are now drive 1/10, lift 2/3 and intake 4.

Also, can I change the drive to the right stick, lift to channel 5 and intake to 6?