How to write this Function in C++ ?(RobotC to C++)

  1. 2 months ago


    Nov 8 Hopkinton, MA, 01748 2602J

    I've been writing some code for a competition next week, and I can't figure out how to write this common function in C++. Here is the code in Robot C.

    #pragma config(Motor,  port1,           leftFront,     tmotorVex393_HBridge, openLoop)
    #pragma config(Motor,  port2,           leftBack,      tmotorVex393_MC29, openLoop)
    #pragma config(Motor,  port3,           rightFront,    tmotorVex393_MC29, openLoop, reversed)
    #pragma config(Motor,  port4,           rightBack,     tmotorVex393_MC29, openLoop, reversed)
    //*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
    void baseControl(int leftSpeed, int rightSpeed, int time)
    	motor[leftFront] = leftSpeed;
    	motor[leftBack] = leftSpeed;
    	motor[rightFront] = rightSpeed;
    	motor[rightBack] = rightSpeed;
    	time = wait1Msec(time);
    task main()
    	baseControl(127, 127, 1000);

    Basically, it makes each drive train rotate for a certain amount of power for a certain amount of time. Thanks for the help as always.

  2. jpearman

    Nov 8 Moderator, ROBOTC Tech Support, V5 Beta Moderator Los Angeles 8888
    Edited 2 months ago by jpearman

    It's pretty much going to be the same when written in VEX C++ or C++ Pro. The motors will usually be defined in the configuration page or robot-config.h, but the code will be along these lines.

    using namespace vex;
    vex::motor leftFront( vex::PORT1, gearSetting::ratio18_1 );
    vex::motor leftBack( vex::PORT2, gearSetting::ratio18_1 );
    vex::motor rightFront( vex::PORT3, gearSetting::ratio18_1, true );
    vex::motor rightBack( vex::PORT4, gearSetting::ratio18_1, true );
    void baseControl(int leftSpeed, int rightSpeed, int time)
      //motor[leftFront] = leftSpeed;
      leftFront.spin( fwd, leftSpeed, velocityUnits::rpm );
      //motor[leftBack] = leftSpeed;
      leftBack.spin( fwd, leftSpeed, velocityUnits::rpm );
      //motor[rightFront] = rightSpeed;
      rightFront.spin( fwd, rightSpeed, velocityUnits::rpm );
      //motor[rightBack] = rightSpeed;
      rightBack.spin( fwd, rightSpeed, velocityUnits::rpm );
      //time = wait1Msec(time);
    int main() {
      baseControl(127, 127, 1000);

or Sign Up to reply!