Home > Ideas, Mindstorms > NXT Virtual Subtractor

NXT Virtual Subtractor

October 27th, 2012 Leave a comment Go to comments

Simple software solution that allows to control two independent motors as if they were connected by a subtractor.  

Datasheet:

Completion date: 27/10/2012
Power: electric (NXT brick)
Language: ROBOTC
Bricks: 1
Motors: 2 x NXT motor
Sensors: none

I’m a big fan of controlling NXT-powered models with a control pad, especially in analog mode, with joysticks and speed control. I was looking for a way to easily control two independent propulsion motors, such as left/right motor in the tracked vehicles. Usually the control can be made easy mechanically, using a subtractor, but sometimes there is no space for it, or the propulsion system is under too much stress to use pieces such as differentials. I found a purely software solution that uses just one pad’s joystick to control two independent propulsion motors just as if they were connected with a subtractor, even though the subtractor is not there. The main advantage of this solution is that it enables analog speed control in all possible directions’ combinations.

Virtual subtractor program:

#include "JoystickDriver.c"

task main()
{
  bMotorReflected[motorA] = false;
  bMotorReflected[motorB] = false;
  while(true)
  {
    getJoystickSettings(joystick);
    motor[motorA] = 0;
    motor[motorB] = 0;
    if (joystick.joy1_y1 != -6)
    {
      motor[motorA] = joystick.joy1_y1 / 1.28;
      motor[motorB] = joystick.joy1_y1 / 1.28;

      if (joystick.joy1_x1 != -5)
      {
        motor[motorA] = (joystick.joy1_y1 + joystick.joy1_x1) / 2.56;
        motor[motorB] = (joystick.joy1_y1 - joystick.joy1_x1) / 2.56;
      }
    }
    else if (joystick.joy1_x1 != -5)
    {
      motor[motorA] = joystick.joy1_x1 / 1.28;
      motor[motorB] = joystick.joy1_x1 / -1.28;
    }

    nxtDisplayCenteredTextLine(0, "BATTERY: %3.1fV", nImmediateBatteryLevel / (float) 1000);
    nxtDisplayTextLine(2, "Y1: %d", joystick.joy1_y1);
    nxtDisplayTextLine(3, "X1: %d", joystick.joy1_x1);
  }
}
									

Photos:

1.jpg

Video:

Categories: Ideas, Mindstorms Tags:
  1. Sariel
    May 26th, 2014 at 19:18 | #1

    @EV3fan
    I don’t know ev3 software.

  2. EV3fan
    May 26th, 2014 at 16:58 | #2

    Is it possible to control a robot with a programm written in the ev3 software running on it via such a gamepad? I don’t have any idea how to code in robotc, you know.

  3. EV3fan
    April 26th, 2014 at 10:44 | #3

    to me that’s the most precise tank steering possible – great work, especially programming

  4. Lennart
    April 9th, 2013 at 10:07 | #4

    Oke

  5. Sariel
    April 9th, 2013 at 09:32 | #5

    @Lennart
    I suggest you type “robotc” into Google and click the first link you get.

  6. Lennart
    April 9th, 2013 at 07:35 | #6

    Where can you buy/download that?

  7. April 8th, 2013 at 21:19 | #7

    @Lennart robotC

  8. Lennart
    April 8th, 2013 at 19:07 | #8

    What kind of software do you use?

  9. March 7th, 2013 at 14:19 | #9

    @Sariel
    Ok thanks! See my site for nxt & PF creations!
    Nxt45.wordpress.com

  10. Sariel
    March 7th, 2013 at 14:01 | #10

    @Nxt45
    Well, it works for me.

  11. March 7th, 2013 at 13:03 | #11

    @Sariel
    I downloaded robotC 3.05 and it did not work it just came up with errors.

  12. Sariel
    March 7th, 2013 at 09:28 | #12

    @NXT45
    Obviously, that’s why it’s not called 3.05 anymore.

  13. March 7th, 2013 at 02:17 | #13

    @Sariel
    Is ther any differenc between 3.05 and 3.51?

  14. March 7th, 2013 at 00:31 | #14

    @Sariel
    Thanks!

  15. Sariel
    March 6th, 2013 at 23:09 | #15

    @NXT45
    3.05

  16. March 6th, 2013 at 23:07 | #16

    Hi! What kind of RobotC is this? 3.54?

  17. Sariel
    December 10th, 2012 at 10:36 | #17

    @Marcky
    There’s a pre-made driver for it in the ROBOTC.

  18. December 10th, 2012 at 09:51 | #18

    I hope this is not a stupid question with an obvious answer, but how do you interface the joystick with the NXT unit?

  19. Bartłomiej
    October 27th, 2012 at 20:21 | #19

    Witam. Chciałem powiedzieć, że zamiast pada zawsze możesz wykorzystać układ sterowany żyroskopem 😉 na warsztatach z robotyki zbudowaliśmy platformę na gąsienicach sterowaną właśnie dwoma “pilotami” z żyroskopami. Gąsienice są sterowane niezależnie, każda ma swój silnik. Zamieszczam filmik ze sprawozdaniem z tych warsztatów. Czasem widać na rękach dwa “piloty” oraz tą platformę. Mogę też poszukać i wysłać na maila kilka zdjęć tej konstrukcji. http://youtu.be/aCSrWavjhVM?t=5m4s

  1. No trackbacks yet.