Go to Post I always felt people get too caught up in the robot and don't see what really makes the teams function so well is the organization itself. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-03-2015, 09:48
ashb1025 ashb1025 is offline
Registered User
FTC #6095
 
Join Date: Feb 2014
Location: New Castle, IN
Posts: 11
ashb1025 is an unknown quantity at this point
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   Spotlight this post!  
Unread 05-03-2015, 10:37
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Autonomous Programming Help

How are you using it?
What do you expect it to do?
What does it do instead?
  #3   Spotlight this post!  
Unread 06-03-2015, 03:26
chloe's Avatar
chloe chloe is offline
human
FRC #1868 (Space Cookies)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2013
Location: United States
Posts: 17
chloe is an unknown quantity at this point
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   Spotlight this post!  
Unread 06-03-2015, 07:59
rich2202 rich2202 is offline
Registered User
FRC #2202 (BEAST Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 1,242
rich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond reputerich2202 has a reputation beyond repute
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   Spotlight this post!  
Unread 06-03-2015, 08:16
ashb1025 ashb1025 is offline
Registered User
FTC #6095
 
Join Date: Feb 2014
Location: New Castle, IN
Posts: 11
ashb1025 is an unknown quantity at this point
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   Spotlight this post!  
Unread 06-03-2015, 08:49
ashb1025 ashb1025 is offline
Registered User
FTC #6095
 
Join Date: Feb 2014
Location: New Castle, IN
Posts: 11
ashb1025 is an unknown quantity at this point
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   Spotlight this post!  
Unread 06-03-2015, 09:13
ashb1025 ashb1025 is offline
Registered User
FTC #6095
 
Join Date: Feb 2014
Location: New Castle, IN
Posts: 11
ashb1025 is an unknown quantity at this point
Re: Autonomous Programming Help

It works! Thanks for all the feedback on this it was really helpful.
  #8   Spotlight this post!  
Unread 06-03-2015, 14:45
budman budman is offline
Registered User
FTC #9010 (Robotic Rangers)
Team Role: Coach
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Plano, TX
Posts: 12
budman is an unknown quantity at this point
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 21:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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