Announcement

Collapse
No announcement yet.

RE: ROBOTC Graphical Multitasking

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • RE: ROBOTC Graphical Multitasking

    (For some reason, I can't post a reply to the original question, or any topic in this subforum, strange)

    "Real" multitasking, that is, using tasks, is only possible in the text version of RobotC. But you can do plenty of cooperative multitasking in graphical, especially since it supports variables now.
    Generally speaking, you'd need to resort to event-driven programming and run a bunch of finite state machines (FSM) in your control loop. You also need to avoid "blocking" commands.

    Let me give an example - a typical autonomous program construct would be "forward(...)", which is a blocking command - it starts motors, then waits until the robot drives the prescribed distance before it lets you do something else. A similar thing, as-if-useful in teleop as well, is moveMotor (i.e. for moving an arm to predefined location) - again, it starts the motor, then waits until it reaches the destination (if ever), then lets you do the rest of your program
    A non-blocking variants of above would be setMotorTarget/moveMotorTarget commands - they tell the motor to work independently towards the goal, but the rest of your program can go on.

    So a simple teleop behavior of having preset heights could be as easy as:
    Code:
    repeat(forever) {
      tankDrive(ChD, ChA, 10);
      if (getJoystickValue(BtnEUp) == 1) {
        setMotorTarget(armMotor, presetHeight1);
      } else if (getJoystickValue(BtnEDown) == 1) {
        setMotorTarget(armMotor, presetHeight2);
      }
    }
    For the example with bumper as an end switch, you could still get away with some simple code like:
    Code:
    repeat(forever) {
      tankDrive(ChD, ChA, 10);
      if (getJoystickValue(BtnEUp) == 1) {
        // start elevator up
        setMotor(elevatorMotor, 100);
      } else if (getJoystickValue(BtnEDown) == 1) {
        // start elevator down
        setMotor(elevatorMotor, -100);
      } else if (getBumperValue(upperBumper) == 1) {
        stopMotor(elevatorMotor);
      } else if (getBumperValue(lowerBumper) == 1) {
        stopMotor(elevatorMotor);
      }
    }
    For even more complicated code, you could test for time passed since you started the operation or do more complex things, as long as you stick to non-blocking functions and an infinite control loop.
    But at some point, it's just easier to "export as text" and start using more powerful constructs, tasks and functions.
Working...
X