Looking for cool programming tricks

Hello, i’m new to VEXcode V5 text, i used robotc in VEX IQ so i’m not a newbie when it comes to programming but with brand new commands and syntax and everything i’m down to the basics again, i’ve seen a bit from others and the examples but i want to know some cool tricks or shortcuts.
Any one that will save space, increase organization, or just overall overlooked commands would be great!
one thing in particular i’m looking for though is how to make 2 or more motors move with one motor.spin command

2 Likes

Motorgroup is your friend @LAMMAZ

vex::motor LT (vex::PORT1);
vex::motor LB (vex::PORT2);
vex::motor RT (vex::PORT3,true);
vex::motor RB (vex::PORT4,true);

vex::motor_group left (LT , LB);
vex::motor_group right (RT , RB);

You can then say

left.spin(fwd,100,velocityUnits::pct);

And both motors specified in the group will move. Jpearman posted about it here when the commands were first introduced.

4 Likes

Nice, this’ll be very useful thanks!

It sure is, I used it this weekend when I updated my 4 motor mecanum pushbot to an 8 motor pushbot. Previously motors were declared like this.

vex::motor m_lb(  PORT1, vex::gearSetting::ratio36_1, true );
vex::motor m_lf(  PORT2, vex::gearSetting::ratio36_1, true );
vex::motor m_rf(  PORT9, vex::gearSetting::ratio36_1 );
vex::motor m_rb( PORT10, vex::gearSetting::ratio36_1 );

and all it took to do the update was redefine like this.

vex::motor m_lb1(  PORT1, vex::gearSetting::ratio36_1, true );
vex::motor m_lb2( PORT11, vex::gearSetting::ratio36_1 );

vex::motor m_lf1(  PORT2, vex::gearSetting::ratio36_1, true );
vex::motor m_lf2(  PORT3, vex::gearSetting::ratio36_1 );

vex::motor m_rf1(  PORT9, vex::gearSetting::ratio36_1 );
vex::motor m_rf2(  PORT8, vex::gearSetting::ratio36_1, true );

vex::motor m_rb1( PORT10, vex::gearSetting::ratio36_1 );
vex::motor m_rb2( PORT20, vex::gearSetting::ratio36_1, true );

vex::motor_group  m_lb( m_lb1, m_lb2 );
vex::motor_group  m_lf( m_lf1, m_lf2 );
vex::motor_group  m_rf( m_rf1, m_rf2 );
vex::motor_group  m_rb( m_rb1, m_rb2 );

no other changes to the rest of the code at all.

the API will change slightly with VEXcode 1.0, some additional class member functions to bring it completely in line with the motor API.

4 Likes

Another thing I saw is using limit switches and the like to toggle the autonomous

Most teams use potentiometers for that. Limit switches are used as a more sensitive touch sensor (sometimes for shooters to detect if a ball is ready to be shot).

1 Like

How would a potentiometer be used for that?

Is there a way to define a variable as a string of code? Like for turning 90 degrees on the robot I could just type in something like turn_left(1)? (the one would be for how many times)

I think you’re looking for a function. You type in the name of the function and any extra criteria, and the code will call it when it gets to it.

1 Like

Tricks: its hard
Harder
And hardest

Simple tank drive program…

#include "vex.h"
#define open {
#define close }
#define end ;
#define f(a) for(a){
using namespace vex end
motor mm[] = {0, 1, 2, 3}end
motor_group m[] = {{mm[0], mm[1]}, {mm[2], mm[3]}}end
controller mc end

int main()
open
f(;;)
m[0].spin(0, mc.Axis3.value(), 0)end
m[1].spin(0, mc.Axis2.value(), 0)end
close
close

Please don’t actual program like this.

5 Likes

Well yeah, but if you take the tab off of it it’s a very small (and rather resistant) button

Where as the limit switch is binary, the potentiometer is analog. This lets you add many more autos with just a single sensor. So instead of having if(limitsensor) blueAuto(); you do if(pot > 1000 && pot < 2000) blueFrontAuto();.

Also a good site is Renegade Robotic’s. It is outdated as all the examples use RobotC and the Cortex’s, but it should be simple enough to apply that knowledge to the V5 system and VexCode. Also V5 has built in encoders with easy to use PID prewritten for you, so I would advise using it. It will make everything easier for the driver and more consistent.

1 Like

Thanks we might be implementing that

Does motor group work for Pros?

Okapilib implements a MotorGroup that operates in much the same way as VEXCode.

I just finished writing my code in VEXcode, and decided to rewrite the entire thing in PROS. Didn’t realize how much PROS had to offer haha