Using Motor Groups to make smart drive

So I’m trying to see if I can make a smart drive using the new motor groups, but for some odd reason, the code used in the old “Smart Drive” Post does not recognize the intertial sensor I have installed.

Not sure how to fix this, still a newb to coding, wondering if anyone can give me a hand?

Here’s my code and a screen shot of my devices:

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// LeftDrive            motor_group   1, 11           
// RightDrive           motor_group   10, 18          
// Controller1          controller                    
// GPS19                gps           19              
// Optical13            optical       13              
// Distance8            distance      8               
// BumperE              bumper        E               
// LimitSwitchD         limit         D               
// LineTrackerF         line          F               
// Inertial15           inertial      15              
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;
smartdrive robotDrive(LeftDrive, RightDrive, Intertial15, 12.56, 16, 16, distanceUnits::in);
// define your global instances of motors and other devices here

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the V5 has been powered on and        */
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

void pre_auton(void) {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // All activities that occur before the competition starts
  // Example: clearing encoders, setting servo positions, ...
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void autonomous(void) {
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              User Control Task                            */
/*                                                                           */
/*  This task is used to control your robot during the user control phase of */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

void usercontrol(void) {
  // User control code here, inside the loop
  while (1) {
    // This is the main execution loop for the user control program.
    // Each time through the loop your program should update motor + servo
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
    // ........................................................................

    wait(20, msec); // Sleep the task for a short amount of time to
                    // prevent wasted resources.
  }
}

//
// Main will set up the competition functions and callbacks.
//
int main() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}

In future, please wrap your code in [code]...[/code] tags for formatting.

If you just want to configure the smartdrive in the graphical UI, no need to configure the motor groups or inertial sensor first – just set up a 4-motor drivetrain and it will ask you what ports everything is on.

If you want to keep the motor groups and inertial sensor configured separately, you could also create the smart drive in your code by adding this code near the top of your main.cpp:

const double wheel_travel = 12.56; // circumference of your wheels in inches; 12.56 is the value for 4" wheels
const int track_width = 16; // track width = distance between two wheels on opposite sides (front-left to front-right)
const int wheelbase = 12; // wheelbase = center-to-center distance between two wheels on the same side (front-left to rear-left)
smartdrive mySmartdrive(LeftDrive, RightDrive, Inertial15, wheel_travel, track_width, wheelbase, distanceUnits::in);
3 Likes

Sorry I should of put more context and sorry bout the code thing, I didnt know about that, havent posted much since I started this account.

Here’s the robot I’m trying to program, made our own sensor bot, but made it with Mecanum wheels, hence why I was trying to use motor groups since the 4 motor drive wouldnt work.

So I tried adding that part of the code in, thank you for that, it will make it easier to explain everything in coding.

I’m still getting an error for Intertial15 (use of undeclared identifier “Intertial15”). Not sure why its giving me an error.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       frankiedonahue                                            */
/*    Created:      Fri Sep 03 2021                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// LeftDrive            motor_group   1, 11           
// RightDrive           motor_group   10, 18          
// GPS19                gps           19              
// Inertial15           inertial      15              
// Distance8            distance      8               
// Optical13            optical       13              
// BumperE              bumper        E               
// LimitSwitchD         limit         D               
// LineTrackerF         line          F               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;


const double wheel_travel = 12.56; // circumference of your wheels in inches; 12.56 is the value for 4" wheels
const int track_width = 16; // track width = distance between two wheels on opposite sides (front-left to front-right)
const int wheelbase = 12; // wheelbase = center-to-center distance between two wheels on the same side (front-left to rear-left)
smartdrive robotDrive(LeftDrive, RightDrive, Intertial15, wheel_travel, track_width, wheelbase, distanceUnits::in);

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
}

Looks like a typo in your code – the device is called Inertial15 but in your call to the smartdrive constructor it’s Intertial15 (with an extra t between the n and e).

In any case, VEXcode’s built-in smartdrive object does not support mecanum drivetrains, whether you configure it in the graphical menu or in your main.cpp. Driving forward and turning will work, but the additional functionality introduced by mecanum wheels (i.e. strafing) will not be supported. Also, you probably don’t want to group the drive motors on each side together, since to move in any direction other than forward or backward, wheels on the same side will need to move in different directions and/or at different speeds.

If you haven’t yet, I suggest reading up on how mecanum wheels work and how they can be programmed – a forum search for “mecanum programming” returned lots of useful-looking results.

And since someone else will mention it if I don’t – you could also consider switching to PROS, the equivalent classes to VEXcode’s smartdrive in PROS/okapilib support a wider array of drivetrain types, including mecanum drive.

6 Likes

is that VexCode Pro? or just the Pros programing platform?

I don’t think you can use Motor Groups with mecanum wheels. Motor Groups are used when you want to control multiple motors as if they are a single motor. This is usually done when multiple motors are mechanically linked (2 chained wheels on one side of the robot, 2 motors driving the same lift, that sort of thing).

For a mecanum drive to be able to be fully utilized, you need to be able to control each motor separately. You will need to create your own functions to implement things.

I would strongly recommend you calculate all of the motor speeds, then assign them to all 4 motors in 4 adjacent code lines. You can get some weird handling if the motor speeds change at different times.

A basic mecanum drive isn’t really that complicated to program. Once you get it running, there are a TON of refinements you will be able to do if you want…

Good luck!

4 Likes

As others have indicated, the default smartdrive object is for 4 inline wheels, and does not support mecannum and strafing. However, you can make a separate smartdrive object for strafing that you call when you want to strafe. You will need to visualize what wheels need to turn what direction to go, say left - which can be the forward of that smartdrive object when you tell that object to TURN left. Off the top of my head, I think that means that wheels on diagonal corners would be grouped as left or right. (Could be easier to write your own method.)

3 Likes

My previous teams who moved on to high school were able to code it by different lines, I’m just trying to find simpler ways to do so, since they moved on to high school, and I got a fresh batch of kids that have no experience in coding or building. Thank you for the input though, I haven’t coded this much since my high school kids, most of them have passed down their knowledge to my current kids, but I need to start learning myself when they graduate or decide not to do robotics anymore.

Thank you everyone for your input, I really appreciate it.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.