Do you use RobotC features like slaveMotor

RobotC has lots of features, most of which I mostly don’t use since I’m used to hardcoding.


// Motors on ports 3, 4 & 5 will follow the motor on port 2
slaveMotor(port3, port2); slaveMotor(port4, port2); slaveMotor(port5, port2);

And then when you go: motor[port2] = 127;

They all move together

This is the first year that I’ve used four motors tied together. I ended up making a function

void shooter (int ShooterSpeed); {
motor[port2] = motor[port3] = motor[port4] = motor[port5] = ShooterSpeed;

Is there some inherent value in using slaveMotor over a function, or indeed hand coding it in the two places in the code?

I certainly can’t speak for other people but the main reason I use the slavemotor function is simply because it’s a bit more compact than making a function for it.

I have always used my own functions, mostly because they are mine and I can edit them, if they ever needed to be, not a very good reason but it is one of the only I could think of.

The use is for when you use ROBOTC built in PID. The internal PID of 1 motor could then drive the rest of the motors.

I make functions to control various parts of the robot that need to move together, like this:

void setLFly(float power) {
  motor[lFlyTop] = power;
  motor[lFlyBottom] = power;

slaveMotor will do the exact same thing, but I thing that this makes the intent of the code much clearer when read in the context of other code (e.g., seeing setLFly() and having two motors move, rather than seeing

motor[lFlyTop] = 127

and wondering why the lFlyBottom motor is also moving [because of a slaveMotor call earlier in the program]). I also don’t use the RobotC PID, which is the only time where you have to use slaveMotor.

I personally tend to use slaveMotor in conjunction with the #define statement, so that if, for example, we had two flywheel motors, I could simply go:

#pragma config(Motor,  port4,           LFlywheel,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           RFlywheel,        tmotorVex393_MC29, openLoop)

#define Flywheel RFlywheel

//Other stuff

task main()
    slaveMotor(LFlywheel, RFlywheel)
        motor[Flywheel] = 127 //Turns entire flywheel on at max power
        //Other stuff

While I guess it’s a little more work, this solution makes it clearer that you’re manipulating the flywheel as a whole. As an added bonus, it actually also prevents you from accidentally trying to only turn on half a flywheel - which is obviously bad for your robot.

This is just what I personally think/use, but I learned RobotC programming more self-taught than in a formal course, so my conventions might be off of what’s expected.

I use slave motor so that I don’t have to make the function to set both motors and only have to set one. It doesn’t really make much difference but is just a matter of personal preference.

I understand it’s a workaround to make the inbuilt PID work with multiple motors and the single IME. It’s a simple syntax to make it work. Could have been in the Motor menu and then part of the pragma. (Going to guess there were more than two emails in the internal Robomatter team discussion on how to implement it)

I’m interested if people use it other than with the built in IME/PID. @Evan10s and I do functions. I’m not sure I’d do @BobTheBlob’s method with the define name change since I’d be looking in the Motor Menu for Flywheel and be wondering why I can’t find it.

I try to write the simplest code possible since I’m either teaching new programmers, debugging messy roboteer code in the pits with minutes to go to their next match, or writing code that once it works I may not look at for months and months. I subscribe to the “less is more” world outlook I mean “less confusion is always moar better” :slight_smile: I also tend not to use extensions (slaveMotor) since I reuse code that works in other places. Sometimes they don’t have that extension.