View unanswered posts | View active topics It is currently Mon Jun 18, 2018 3:33 pm

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Programming the LEGO m Motor with RobotC
Author Message
Rookie

Joined: Wed Nov 28, 2012 4:46 pm
Posts: 1
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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.
 Code:#define DEADBAND_THRESHOLD 15#define DEADBAND(x) ((abs(x) >= DEADBAND_THRESHOLD)? x: 0)#define BOUND(x) (((x) > 100)? 100: ((x) < -100)? -100: (x))#define JOYSTICK_POWER(x) (BOUND(DEADBAND(x)))#define CLAW_CLOSE_ANGLE 0#define CLAW_OPEN_ANGLE 120task 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.        //        getJoystickSettings(joystick);        //        // 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;        }        else        {            motor[clawMotor] = 0;        }        wait1Msec(100);    }}

Wed Nov 28, 2012 7:02 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning