RobotC Slavemotor cmd question

I have switched to RobotC in the past few weeks and it has been a learning experience. But I get the jist of all the commands and flow of things.
My students have started messing around with PID control and I am having to track down a problem. I am not sure where he got the code, but I do know that he copied and pasted. So… I am trying to find out solutions so I can teach them and learn. Nothing like being on a tight timeline.

I went through the code and noticed he had many slavemotor commands, and they were slaved to many different motors. The shooter motor with the encoder is port 7 and the other motor is port 8. My question is in the motor setup he only has port 7 checked for PID. Should he also checked PID for port 8?

The motors are not spooling up to speed like they should so I am trying to That is another problem. Right now I am just trying to sort it out.
I hope the attached file works in the zip, but look inside and find clustercrap.c

Thanks for any and all help
ddd.zip (21.2 KB)

I have found my shooter to be about the same consistency with left and right independent. Slave motor just means both motors will receive the same power levels always. If the getting up to speed is too slow then tweak the kp, ki, and kd values. More about PID tuning can be found online and on the forums.

Well the problem they had before in EasyC was that the motor would slow down too much after a ball shot. They switched out to RobotC and PID to be able to keep the flywheel up to speed better.

If you are unsure how PID works then I wouldn’t use it. It is never a good idea to use code that you don’t understand. Bang-bang is a much simpler version of speed control. You can find examples of it on the forums.

While I agree that using code you don’t understand isn’t a good idea, rather than do something you do understand, learn about PID. Just the Wikipedia article is pretty useful, and the forums have tons of support for it.

Well I have learned about PID theory and understand it. The code is what I am having to learn. I do not agree with what the student did by just copy and paste. I got his program and there is basically nothing in there about PID.

But my original question was in the motor setup… on the shooter there are 2 motors… port 7 with an IME and PID is checked. then you have port 8 which is slaved to 7. Should port 8 be checked off as PID?

I am learning by jumping in this weekend and hashing my own code out. The student will be taught later after I get it working. I am kind of PO’d at them because he fronted that he had it working and the code was done. He basically lied to me. So I am working in the background to learn and master it.

There should only be one slave motor command to slave port 8 to port 7. I don’t know what the other slave commands are, since I can’t look at the code on an iOS device and I don’t have access to my laptop right now, but what exactly is the issue? Is it just that the motors are not spinning up fast enough, or is there an issue with the code throwing errors/warnings?
My understanding of the slave motor command is that it basically behaves like 2 motors y-cabled; you command the master motor, and it controls the slave motor as well. You cannot use either independently of the other. As long as the motors are not fighting each other, it should be fine.

Yeah the motor speed is one thing that happened. I am going to hash out some code tonight and that slave issue was my first to go after. I do not know where he got the code, but I am starting from scratch. I don’t even see any PID code in there so either I am looking at it wrong or he does not know anything about it at all. Thanks for that help. Hopefully we can figure it out ASAP. TSA state is Tuesday then nationals a week later… then off to World’s. Hopefully we will get it hashed out.
Thanks

No, where a motor is slaved, only the Master motor needs PID control. Because he is using the built-in PID function, no extra program steps are needed. Be sure to check and set all 9 of the PID settings, specially the proportional, integral, and derivative factors in the PID Settings screen located under the Motor and Sensor Setup pull-down tab. Some of the “standard” settings for the 393 Motors may not be correct for your particular set-up.

For my robot, with BEST Small Motors P/N 276-1610 and the red Optical Shaft Encoder #276-2156, the normal “3-Wire Motor” type on the pull-down menu under the Motor and Sensor Setup will not work with the new RobotC built-in PID function. I have to use the “269” or “393” motor types, but change the “Maximum Encoder Counts per Second” from 1000 to 600. This calculated value is found by : Integer of 200 to 1000 = [90 Motor RPM = 90 Rev/min X 1min/60sec X 360 Counts/Rev] = 540 or next largest acceptable integer = 600 counts/sec).

Thanks for the help. I will tweak it. I was not sure about the built in PID functions but I will work on it for sure.
Do you find the built in just as functional as doing the code yourself?
Thanks

I personally prefer writing my own PID code. This gives me a better understanding of what goes on in my program, so I can debug it more easily and explain it to judges during interviews (always a plus). I also get to play around with variations. It also has the added bonus of being an extra 20 - 50 lines of code each time for an engineering notebook.
I’m sure the built-in PID is just as useful as a handwritten function, but I haven’t used it at all.

Thanks for the advice and help