View unanswered posts | View active topics It is currently Sat Sep 26, 2020 2:00 am

Reply to topic  [ 2 posts ] 
Programming the LEGO m Motor with RobotC 
Author Message

Joined: Wed Nov 28, 2012 4:46 pm
Posts: 1
Post Programming the LEGO m Motor with RobotC
My FTC team is having difficulty programming the Lego M motor using RobotC. We are using this motor to control our claw that picks up the rings in the 2012 game. However, we only have the functionality to fully open the claw (almost to the point of breaking) and to fully close it. We cannot figure out how to get the program right in order to have more control over the claw's functionality. Anyone know of a good reference we can look at for info on how to program this special type of motor. My team seems to think it more so designed for programming in LabView, but there must be a way to control it with RobotC. Please help!

Many Thanks!

Wed Nov 28, 2012 4:50 pm
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Programming the LEGO m Motor with RobotC
The LEGO motors have built-in encoders. So assuming your claw is closed to start with and assuming you want to use the joystick to control it. Here is an example on how to do it. It's not the best code but it's simple.
#define DEADBAND(x) ((abs(x) >= DEADBAND_THRESHOLD)? x: 0)
#define BOUND(x) (((x) > 100)? 100: ((x) < -100)? -100: (x))

#define CLAW_OPEN_ANGLE 120

task main()
    //Assume the claw is closed at start and the encoder value goes up when opening.
    nMotorEncoder[clawMotor] = CLAW_CLOSE_ANGLE;
    while (true)
        // Get joystick readings.

        // Translate controller 2 right stick x axis value to within motor power range (-100 to 100) and with deadband.
        int clawPower = JOYSTICK_POWER(joystick.joy2_x1);

        // Read the current claw angle.
        int clawPos = nMotorEncoder[clawMotor];

        // Only allow the motor to move if we are opening and it's not fully opened
        // or we are closing but it's not fully closed.
        if ((clawPower > 0) && (clawPos < CLAW_OPEN_ANGLE) ||
            (clawPower < 0) && (clawPos > CLAW_CLOSE_ANGLE))
            motor[clawMotor] = clawPower;
            motor[clawMotor] = 0;

Wed Nov 28, 2012 7:02 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.