How to crate a macro btw two different mechanical systems

We do not know how to create a macro that allows every time btn a is pressed that the tray will move forward x degrees, and at the same time the lift will move up at y degrees all in one fluid motion.

If you are using shaft encoders, store the current values in variables, and set them to move however many degrees you need. If you are using potentiometers or no sensors, print the values to the controller or brain before the motion, then record the new values after the motion. For potentiometers, just move the motors until they read the recorded final value. For the built in encoders, spin the motors until the recorded change in values is met. This can be further controlled with PID.

1 Like

I would suggest running a PID on the lift and a PID on the tray, so all you would need to do is set desired angle to what you need. Have two chains of if statements, one to change desired angle for lift and the other for the desired angle for the tray, and have the desired angle change depending on the button with addition to both chains containing the if statement of the button you want the macros.
Hopefully this makes sense.
(This is not code, but more or less a flow chart of what I mean so you can make code. The macro button is L2)

while(1==1){

if L1{
trayDesired = 10;
}
else if L2{
trayDesired = 30;
}
else{
trayDesired = 0;
}

if R1{
liftDesired = 30;
}
else if L2{
tliftDesired = 50;
}
else{
liftDesired = 0;
}

tray PID code
traymotor = trayPIDvalue;

lift PID code
liftmotor = liftPIDvalue
}

If you need explanation, just ask :slight_smile:
If you do not know PID, It is very easy and not too difficult to understand.

2 Likes

Yes, sadly we do not know how to create a PID, and so far we have been using the built in encoder values and average angle values

Please, take a look at these macro programming examples:

Please, ask questions if not clear.

2 Likes