Is it considered bad practice to stop cogs within methods? I read that it is to start cogs within methods and this activity should be restricted to main. Does the same apply for stopping?
Where did you read that you should not start COGs inside of a function? I think it's not usual, but not a bad practice. Usually you have COGs which drive a device and as long as you don't run out of COGs you'd simply start them and let em run.
If you have some devices which are only needed from time to time, why not start em when needed wherever they are needed?
If you have such dynamic COG requests, you should only make sure that the code can handle the case that no COGs are available.
With stopping COGs within a function you mean the COG stops itself? That's no problem, as the code in the COG then knows if stopping is fine.
Or do you mean a COG stops another one? There are cases where it's fine and others where you should at least sync with the COG to be stopped. For example if the COG only drives some LED's ... no problem. If it runs a motor it might be a bad idea to simply stop that COG. All outputs run by that COG will go to high impedance mode. Whatever that means for the motor ... running without control or doing a full break ... depends on the cirquit ... and it can cause damage either way.
So in this case it would definitely be better to tell the COG that it should stop and wait until it came to a defined end.
Comments
If you have some devices which are only needed from time to time, why not start em when needed wherever they are needed?
If you have such dynamic COG requests, you should only make sure that the code can handle the case that no COGs are available.
With stopping COGs within a function you mean the COG stops itself? That's no problem, as the code in the COG then knows if stopping is fine.
Or do you mean a COG stops another one? There are cases where it's fine and others where you should at least sync with the COG to be stopped. For example if the COG only drives some LED's ... no problem. If it runs a motor it might be a bad idea to simply stop that COG. All outputs run by that COG will go to high impedance mode. Whatever that means for the motor ... running without control or doing a full break ... depends on the cirquit ... and it can cause damage either way.
So in this case it would definitely be better to tell the COG that it should stop and wait until it came to a defined end.