I’ve been glancing through the RobotC Includes, and I can’t find any typedefs for “task”. Is a task a modification in the compiler that handles it by default, or is it defined somewhere?
Also, does anyone know if it’s possible to use functions in RobotC that return data (instead of just a void or a task, which are the only ones they have listed under C Constructs).
Thanks for any information you can offer, I’m trying to learn this well enough to teach confidently to a class full of kids in a couple of weeks, and it’s slight dissimilarities to C are getting to me…
I’m not sure exactly how much Java you know, but RobotC resembles Java on a great scale.
I’m not entirely sure of the tasks issue you’re having as I have not worked with tasks myself.
And you definitely can create a function to return data. Generally, I used return data functions to do conversion for FTC joystick controls, but the way to do it is
int functioname (int a)
where the first ‘int’ is the type of data you are returning.
the ‘functioname’ is the name of the funciton
and the second ‘int’ is the type of data you are inputting.
and the ‘a’ is the name of the data you’re inputting (for the particular function)
To return the value, in the function block, just type ‘return b’
Where b is some value whose type matches the output type you set the function to.
Hope that helps. PM me for more.
Yeah, that’s the standard C way of returning values, just didn’t know if it worked or not (haven’t had time to reload the firmware on my VEX robot and do debugging yet). Thanks for letting me know!
After doing a little bit of research, it looks like they have extensively modified the compiler to slim it down. For one thing, there’s no pointers, which is a standard C concept available in all real C compilers. This leads me to believe that they have built “task” into the compiler itself and not declared it anywhere. Oh well, I was just wondering if I could find its declaration to figure out its properties a little better (i.e. why you have to use StartTask() and StopTask() instead of just calling it like a function).
After modifying and compiling a fairly complex program I wrote in WPILib and then in Default code onto RobotC, it looks like most of the standards work except for pointers. It gave me a warning about embedding a command inside an if statement ( if( (wheel = forward+…)>127) ), so I’ll have to make sure that it works.
And something that’s rarely done in C, but does have to happen occasionally is that multiple C files are included into the project via #include “…” (instead of just headers). You just have to include the other C files into the main project file. Is this just a limitation of the trial version, or something inherent to RobotC as a whole? Just curious, I like to know as much about a programming language/environment as I can before I start teaching it to other people.
Thanks for the information!
I’m not a RobotC expert, but I believe tasks are for asynchronous activities, for multitasking. If you call a function, the current one doesn’t proceed until the called one returns. If you start a task, then the current function and the new task will multitask in parallel. C doesn’t have this as a language notion. It is added with libraries and is often performed with fork() or a similar function which will have #includes defining it. If the file compiles with StartTask() in it, then it is inherent in the language or the default compile includes are broad enough to include the file that defines it. I suspect it is inherent.
The warning about the assignment is probably just making sure that you meant to use = versus ==. This is a common mistake and is hard to see when simply looking at code. So I think the compiler supports the code as written, but wants to warn you that you have an assignment embedded in an expression.
Wow, thank you, that was very helpful!