|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Autonomous Programming Help
Hello, I'm writing the code for our FTC bot in RobotC and I have ran into a bit of trouble trying to optimize the code a bit, I want to be able to define to variable for on string of code in my function like this
void goForward(const int Speed, nTime) { motor[1] = Speed; wait1MSec(nTime); } basically so I can define the speed and how long it runs in the main task without editing the function, but the above code doesn't seem to work, and would greatly appreciate any help. |
|
#2
|
|||||
|
|||||
|
Re: Autonomous Programming Help
How are you using it?
What do you expect it to do? What does it do instead? |
|
#3
|
||||
|
||||
|
Re: Autonomous Programming Help
Maybe I just don't know RobotC, but it looks like before nTime in the parameter list, you don't specify the type.
|
|
#4
|
|||
|
|||
|
Re: Autonomous Programming Help
Does the code work in Teleop? if not, it might have to do with the "heart beat". If the system does not see activity for x milliseconds, it assumes your code has crashed, and disables all outputs (motors). Do you have to restart your robot to get it to run again?
|
|
#5
|
|||
|
|||
|
Re: Autonomous Programming Help
The parameter list is fine I just don't know how to add 2 parameters to 1 function, it works fine if I just have the ntime parameter, but I want to be able to specify the speed of the motors in the main task of the program without changing the function code itself so that I don't have 30+ programs telling it to drive forward. Kinda like this
task main() { goForward(50,1000) { basically saying that the motor should run at 50% power for 1000 milliseconds but I don't know how to set a parameter to the power percentage of the motor when I'm writing the code for the function. and it doesn't even let me run the code it's a compiler error |
|
#6
|
|||
|
|||
|
Re: Autonomous Programming Help
Well I think I have found a solution but I could be wrong, there are no errors when I compile the code but I haven't been able to try it for our NXT is dead at the moment.
Here is a sample of the code void sweepIn(const int Speed, const int nTime) { motor[Sweep] = Speed; wait1Msec(nTime); } I don't think I set the parameter type cause I was thinking that since I had already set it for the function it would carry over to the other parameter. Last edited by ashb1025 : 06-03-2015 at 08:52. |
|
#7
|
|||
|
|||
|
Re: Autonomous Programming Help
It works! Thanks for all the feedback on this it was really helpful.
|
|
#8
|
|||
|
|||
|
Re: Autonomous Programming Help
After waiting the amount of time for the motor to move, you will need to turn the motor off.
For example: void sweepIn(int Speed, int nTime) { motor[Sweep] = Speed; wait1Msec(nTime); motor[Sweep] = 0; } Also, the "const" declarations on the function parameters are not necessary. Just declare as "int". See above in green. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|