I need to test my firmware but I do not have access to the hardware.

I am trying to build some code responsible for navigating our robot around. I have built some code for the task and setup the main routine such that it is able to run a couple automated tests (Move forward, back, rotate, etc…)

The problem is, as I am programming the bot for my school’s vex club, I do not actually have access to the vex robot only to the software which I use to write the code (easyc v4 for Cortex). I can not do any testing until monday, however I would really like to move forward on this project’s code as the competition is within 7 working days.

So I have two questions:

  • Is there anyway to test this code in a simulator? I don’t need a full 3D simulation. Something to confirm the direction the motors are turning would be sufficient.
  • Would anyone here be willing to, out of interest, construct and test a quick model? The base is really quite easy to setup.


The boxes are motors attached to omni-wheels, the numbers represent which motor number they are. The arrows show which direction the motors must rotate when going clockwise. The front of the robot is define by the blue arrow. The base is just a square frame.

If the robot is bug free (I have done as much offline debugging as possible) it should:

  1. Move slowly towards the top-right (see the diagram above for the bot’s front.)
  2. Move quickly towards the Bottom-Right
  3. Move even slower to the bottom-left.
  4. Rotate clockwise quickly
  5. Rotate counter-clockwise slowly.
  6. Stop.

If you’d like, I can upload the compiled .hex program or the source-code if you’re wanting to take a look at it\test it.

Thanks.

This came from your other thread (posted in the “official” section, so regular users can’t answer it). But it’s closely related to the question(s) you have in this thread, so I’m answering both.

The Vex “joystick” shown here is actually similar to a video game controller.

From the top view, it has 2 identical “mushroooms” where you rest your left and right thumbs (what I usually think of as a “joystick” on a game controller, which I will call a “stick” here). Near the right stick is a small label - the L/R arrow is marked “1” and the U/D arrow is marked “2”. The left stick has arrows with 3 (U/D) and 4(L/R) On the top, there are also 2 sets of 4 buttons, each with labels U/D/L/R.

In addition, if you look at the photo of the joystick in the packaging (slightly tilted), you can get a glimpse of 4 buttons on the front, 2 on each side, labeled U/D. If there were a “full frontal view” these would be easier to see.

GetJoystickAnalog gives access to Channels 1-4, since the sticks allow you to control speed in a gradual way. Values are integers ranging from - 127 to + 127, with the stick at “rest” at 0.

GetJoystickDigital gives access to Channels 5 - 8, which are buttons (pressed/not pressed only with digital values 0 or 1). If you select Channel 5 or 6 notice that you get access to 2 buttons (D/U), while selecting Channel 7 or 8 gives access to 4 buttons (D/U/L/R).
The Vex joystick is L/R symmetrical, and the channels are mapped as follows:

Ch 1: Right stick x-axis. Push right gives values 0 to 127, push left gives 0 to -127. If you attach and program motors properly, you can use this stick to make the robot move left and right.
Ch 2: Right stick y-axis
Ch 3: Left stick y-axis
Ch 4: Left stick x-axis
Ch 5: Left side “front buttons” Down/Up (not visible from top view)
Ch 6: Right side “front buttons” D/U
Ch 7: Left side top view 4 buttons D/U/L/R
Ch 8: Right side top view 4 buttons D/U/L/R

You can upload your code for a look-over, but I don’t know of a simulator or have hardware to test it, either.

The cool part of EasyCv4, is that it has a command that automatically maps the sticks to control a holonomic drive (your configuration). The Holonomic command under the Joystick menu shows a diagram of how to connect your motors. It programs the right “stick” to shift D/U/L/R, and the left stick to spin clockwise or counterclockwise (just like Halo).

If you are programming to move autonomously, this is fairly straightforward, too. Suppose you connect your motors to ports 2, 3, 4,5, labeling clockwise (like in the diagram for the holonomic drive). Driving all 4 motors in the same direction will cause it to spin. To drive straight, power the even motors (2 and 4) in the same direction (say + 127) and the odd motors (3 and 5) in the opposite direction (say - 127)

Thanks for your response!

Your description of the controller’s joystick (or rather the joysticks sticks) was very clear & understandable. Thanks.

I would really appreciate it if you (or others) were willing to take a quick look over the code. I am not sure how easy it is to get around with so little comments (Sorry about that.). But I can give a basic description of the design model below. (I have attached the whole easyC project.)

Regarding the driving of the robot, I have actually created an abstract Driver class that’s inherited by two others, AIDriver and UserDriver. (Okay, I know there aren’t any classes in C, but we find ways, lol. Basically I just implemented classes & virtual functions as a C++ compiler would - AFAIK the way I did it is the most common). I did this so that I could create a line-follower & navigator just by simply inheriting a fairly basic Driver object & adding some AI to it.

So the base is an abstract class, Driver. Which handles:
-Functions to move in a direction described by a unit vector.
-Functions to move at a speed described by a float member.
-Functions to switch between SpotRotation and Movement(Translation) mode.
-Configures the robots wheels (Each wheel is accessed through a Wheel object). They’re inverted if they do no rotate such that they are either rotating clockwise to the right or clockwise upward. So the right and rear wheel would be inverted (meaning if you gave the inverted wheels a velocity of 127pwm it would rotate counter-clockwise)
-Nothing is stopping you, other than the fact that the virtual function table has not been initialized, from using this as a normal object so I did just that to test it in Robot.c

Then there is the UserDriver that inherits Driver.

  • Basically the Driver object except that it communicates with the joystick.

Then there is the AIDriver that I haven’t fully planned out yet but I plan on adding some line-following capabilities.

Anyway, the design I am going for doesn’t let me directly bind the controller to the motors if I want to keep it flexible.

Feel free to outright criticize my code. This is my first time programming a VEX bot and I could really use the feedback.

edit
Driver_dtor is described differently in the source file than it is in the header. I don’t know why it even compiled. Anyway, fix:
the Driver_dtor in the header to:
void Driver_dtor(DRIVER* const pDriver);

edit
Wheel_syncWheel in Wheel.c set the velocity incorrectly - multiplied by MAXSPEED twice instead of once. Fixed it to:


void Wheel_syncWheel(const WHEEL* const pWheel)
{
	SetMotor(pWheel->m_bMotorNumber, floor( .5F + WHEEL_MAXSPEED * (CLAMP(pWheel->m_fVelocity, -1.0F, 1.0F)) * (pWheel->m_isInverted ? -1 : 1))); 
}

edit
I just removed the attachment, I will upload the fixed on in a moment or two. Also, after fixing it I plugged it MSVC++ and made set-motor trace its arguments to the console. It seems to be setting the motor pwm correctly for all the motors. I would still appreciate it if someone uploaded it to a bot or commented on the code :slight_smile:

Sorry for the double post, it just seems more proper if I place this comment seperately. I’ve attached the fixed (hopefully completely) project to this post.

So I’ve fixed all the bugs I can find and have run the code in MSVC++ 2k8 only I traced the arguments of all the calls to SetMotor and the driver seems to be setting up the motors properly. I would still appreciate it if someone uploaded it to a bot or commented on the code.
SchoolRobot.zip (53.2 KB)

Took a look-over, but I can’t get a "lock"on what it does – programming is not my forte. Perhaps one of the other users will pick this one up.

I took a quick look, and I mean quick, perhaps 5 minutes, I will run it on my cortex tomorrow. You obviously have a background in object oriented programming and perhaps ported this code from another environment. It looks like solid code and is certainly using techniques that are beyond most EasyC programmers on this forum. EasyC does not have a simulator but perhaps you could add some “PrintToScreen” statements (essentially printf) so you could monitor the values going to your wheels in the Wheel_syncWheel function. Anyway, as I said I will give you some more feedback tomorrow.

Thanks! This forum is awesome. I really appreciate the time from the both of your guys :slight_smile:

Jeremy

Your code successfully runs on the cortex, I’m not going to do the math and check your algorithm but I did add a few PrintToScreen statements so you can compare the output to what you are expecting, hopefully this is self explanatory but I suppose the key lines are the setting of the motor speeds such as “Wheel Sync motor(5) = 45” etc. If you use PrintToScreen it can be a bit flakey and I tend to add a delay of 100mS after each line so output is not lost. Let me know if you have any questions.

This is an example of the type of things I added.


void Wheel_setVelocity(WHEEL* const pWheel, const float fVelocity)
{
    PrintToScreen("Wheel set velocity\n");
    Wait(100);

    if(pWheel->m_fVelocity == fVelocity)
        {
        PrintToScreen("Velocity Matched %d %f\n", pWheel->m_bMotorNumber, fVelocity );
        Wait(100);
        return;
        }

    PrintToScreen("Velocity Set %d %f\n", pWheel->m_bMotorNumber, fVelocity );
    Wait(100);

    pWheel->m_fVelocity = fVelocity;
    Wheel_syncWheel(pWheel);
}
Driver Init
Wheel Init motor(2)
Wheel Sync motor(2) = 0
Wheel Init motor(3)
Wheel Sync motor(3) = 0
Wheel Init motor(4)
Wheel Sync motor(4) = 0
Wheel Init motor(5)
Wheel Sync motor(5) = 0
Driver Sync
Wheel set velocity
Velocity Matched 2 0.000000
Wheel set velocity
Velocity Matched 4 0.000000
Wheel set velocity
Velocity Matched 3 0.000000
Wheel set velocity
Velocity Matched 5 0.000000
Start Tests
Driver Sync
Wheel set velocity
Velocity Matched 2 0.000000
Wheel set velocity
Velocity Matched 4 0.000000
Wheel set velocity
Velocity Matched 3 0.000000
Wheel set velocity
Velocity Matched 5 0.000000


test1
Driver Set Direction 1.000000,1.000000
Driver Sync
Wheel set velocity
Velocity Matched 2 0.000000
Wheel set velocity
Velocity Matched 4 0.000000
Wheel set velocity
Velocity Matched 3 0.000000
Wheel set velocity
Velocity Matched 5 0.000000
Driver Set Speed 0.500000
Driver Sync
Wheel set velocity
Velocity Set 2 0.353553
Wheel Sync motor(2) = 45
Wheel set velocity
Velocity Set 4 0.353553
Wheel Sync motor(4) = -45
Wheel set velocity
Velocity Set 3 0.353553
Wheel Sync motor(3) = -45
Wheel set velocity
Velocity Set 5 0.353553
Wheel Sync motor(5) = 45


test2
Driver Set Direction 1.000000,-1.000000
Driver Sync
Wheel set velocity
Velocity Matched 2 0.353553
Wheel set velocity
Velocity Matched 4 0.353553
Wheel set velocity
Velocity Set 3 -0.353553
Wheel Sync motor(3) = 45
Wheel set velocity
Velocity Set 5 -0.353553
Wheel Sync motor(5) = -45
Driver Set Speed 1.000000
Driver Sync
Wheel set velocity
Velocity Set 2 0.707107
Wheel Sync motor(2) = 90
Wheel set velocity
Velocity Set 4 0.707107
Wheel Sync motor(4) = -90
Wheel set velocity
Velocity Set 3 -0.707107
Wheel Sync motor(3) = 90
Wheel set velocity
Velocity Set 5 -0.707107
Wheel Sync motor(5) = -90


test3
Driver Set Direction -1.000000,-1.000000
Driver Sync
Wheel set velocity
Velocity Set 2 -0.707107
Wheel Sync motor(2) = -90
Wheel set velocity
Velocity Set 4 -0.707107
Wheel Sync motor(4) = 90
Wheel set velocity
Velocity Matched 3 -0.707107
Wheel set velocity
Velocity Matched 5 -0.707107
Driver Set Speed 0.250000
Driver Sync
Wheel set velocity
Velocity Set 2 -0.176777
Wheel Sync motor(2) = -22
Wheel set velocity
Velocity Set 4 -0.176777
Wheel Sync motor(4) = 22
Wheel set velocity
Velocity Set 3 -0.176777
Wheel Sync motor(3) = 22
Wheel set velocity
Velocity Set 5 -0.176777
Wheel Sync motor(5) = -22
Driver Sync
Wheel set velocity
Velocity Set 2 -0.250000
Wheel Sync motor(2) = -32
Wheel set velocity
Velocity Set 4 -0.250000
Wheel Sync motor(4) = 32
Wheel set velocity
Velocity Set 5 -0.250000
Wheel Sync motor(5) = -32
Wheel set velocity
Velocity Set 3 -0.250000
Wheel Sync motor(3) = 32


test4
Set Direction
Driver Set Direction 1.000000,-1.000000
Driver Sync
Wheel set velocity
Velocity Set 2 0.250000
Wheel Sync motor(2) = 32
Wheel set velocity
Velocity Matched 4 -0.250000
Wheel set velocity
Velocity Set 5 0.250000
Wheel Sync motor(5) = 32
Wheel set velocity
Velocity Matched 3 -0.250000
Set Speed
Driver Set Speed 1.000000
Driver Sync
Wheel set velocity
Velocity Set 2 1.000000
Wheel Sync motor(2) = 127
Wheel set velocity
Velocity Set 4 -1.000000
Wheel Sync motor(4) = 127
Wheel set velocity
Velocity Set 5 1.000000
Wheel Sync motor(5) = 127
Wheel set velocity
Velocity Set 3 -1.000000
Wheel Sync motor(3) = 127


test5
Driver Set Direction -1.000000,-1.000000
Driver Sync
Wheel set velocity
Velocity Set 2 -1.000000
Wheel Sync motor(2) = -127
Wheel set velocity
Velocity Matched 4 -1.000000
Wheel set velocity
Velocity Set 5 -1.000000
Wheel Sync motor(5) = -127
Wheel set velocity
Velocity Matched 3 -1.000000
Driver Set Speed 0.500000
Driver Sync
Wheel set velocity
Velocity Set 2 -0.500000
Wheel Sync motor(2) = -63
Wheel set velocity
Velocity Set 4 -0.500000
Wheel Sync motor(4) = 64
Wheel set velocity
Velocity Set 5 -0.500000
Wheel Sync motor(5) = -63
Wheel set velocity
Velocity Set 3 -0.500000
Wheel Sync motor(3) = 64


Done
Driver Set Speed 0.000000
Driver Sync
Wheel set velocity
Velocity Set 2 -0.000000
Wheel Sync motor(2) = 0
Wheel set velocity
Velocity Set 4 -0.000000
Wheel Sync motor(4) = 0
Wheel set velocity
Velocity Set 5 -0.000000
Wheel Sync motor(5) = 0
Wheel set velocity
Velocity Set 3 -0.000000
Wheel Sync motor(3) = 0
Driver Deinit
Driver Sync
Wheel set velocity
Velocity Matched 2 -0.000000
Wheel set velocity
Velocity Matched 4 -0.000000
Wheel set velocity
Velocity Matched 5 -0.000000
Wheel set velocity
Velocity Matched 3 -0.000000
Wheel Deinit
Wheel Deinit
Wheel Deinit
Wheel Deinit

Thanks jpearman, it works exactly as I had expected. I really appreciate that :slight_smile: (Except I just realized I setup the rounding incorrectly, lol. THats a simple fix though :slight_smile: