Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Autonomous Programming Help (http://www.chiefdelphi.com/forums/showthread.php?t=135487)

ashb1025 05-03-2015 09:48

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.

Alan Anderson 05-03-2015 10:37

Re: Autonomous Programming Help
 
How are you using it?
What do you expect it to do?
What does it do instead?

chloe 06-03-2015 03:26

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.

rich2202 06-03-2015 07:59

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?

ashb1025 06-03-2015 08:16

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

ashb1025 06-03-2015 08:49

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.

ashb1025 06-03-2015 09:13

Re: Autonomous Programming Help
 
It works! Thanks for all the feedback on this it was really helpful.

budman 06-03-2015 14:45

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.


All times are GMT -5. The time now is 01:52.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi