Ardway the Intelly-Segway

In this section you will find, where possible, the details of components used to build this robot and specific information about the software and about connections implemented

If you need additional specific information about this topic or if you want to look it personally please write an email

AutoCar

Using a Joystick directly connected to Ardway Digital PINs it is possible to manage engines exactly as a mini cart.
The application written for the Arduino board is able to modulate acceleration using an incremetal algorithm (showed below). This in order to avoid accidents due to the fast acceleration or deceleration
The connection schema is described here

Ardway uses two 250W electric motors. These motors are not stepper motors so must be driven varing the current. This can be done by a driver able to absorbe the extra current and produce the dired voltage.
Usually this is obtained with an H-Bridge controller.
The H-Bridge is designed to drive a motor clockwise and anticlockwise. To reverse a motor, the supply must be reversed and this is what the H-Bridge does.
An H-Bridge can be made with SWITCHES, RELAYS, TRANSISTORS or MOSFETS.
For a project such as a robot or car, we need an ELECTRONIC circuit - one that is controlled by a "CONTROL CIRCUIT". The Control Circuit outputs a signal (or a number of signals) to control an H-Bridge.

Here is a sample circuit. The Control Circuit consists of the first 3 transistors. These amplify the signal from the electret microphone and produce a signal that is able to charge a 47u electrolytic. The next two transistors provide inverted signals to the H-Bridge and are part of the Control Circuit. The H-Bridge consists of the last 4 transistors.

Geeetech i3x Printer

However, in order to move Ardway the two motors used require many ampere to drive over the HBridge and this is not very easy to implement (at least you need to build different protections in your circuit). for this reason the best way is to use a commercial driver. It is not cheap (to drive all the needed ampere) but, believe me, it is less dangerous. I selected one of the best drivers on the market the Saberthooth 2x32

Geeetech i3x Printer

The 2 motors can be controlled using an easy library over the serial port so, in order to use it via Arduino, you will need to connect it to the Serial port of arduino (To be more detailed you will need to be connected to one of the available serial port, depending on which arduino you will use) and send the right commands. In the following c++ code used to run the Ardway Autocar Function, you will not see the protocoll used but the functions defined for each movement of the joystick. Later in the page I will present some example of the protocoll

AutoDrive source code


                        if (currMode == AUTOMODE)       //Drive it manually
                        {


                            //Read Joystick values
                            SteerLeftPin = digitalRead(STEERINGLEFTPIN);
                            SteerRightPin = digitalRead(STEERINGRIGHTPIN);
                            balancelForward = digitalRead(BALANCEFORWARDPIN);
                            balancelBackward = digitalRead(BALANCEBACKWARDPIN);

                            DBGString[0] = '\0';
                            //Maintain maximum speed
                            if (curAutoSpeed > SABER_MOTOR1_HALF_FORWARD)
                                curAutoSpeed = SABER_MOTOR1_HALF_FORWARD;

                            if (SteerLeftPin == 0) {
                                SerialTransfer.isBack = false;
                                if (previousDirection == 99) {
                                    previousDirection = LEFT;
                                    curAutoSpeed = 1;
                                }
                                else if (previousDirection == LEFT)
                                    curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
                                    else    {
                                        previousDirection = LEFT;
                                        curAutoSpeed = 1;
                                    }
                                if ((curAutoSpeed % 5) == 0) { //Delay the string
                                    sprintf(DBGString, "Turn RIGHT: %d\r", curAutoSpeed);   //wrong string due to an error
                                    SerialTransfer.SendDisplayString((char*)DBGString,0);
                                    DBGString[0] = '\0';
                                }
                                //and now turn left
                                autoTurnLeft();
                                delay(50);      //Slow down to delay cicles
                            }
                            else if (SteerRightPin == 0) {
                                SerialTransfer.isBack = false;
                                if (previousDirection == 99) {
                                    previousDirection = RIGHT;
                                    curAutoSpeed = 1;
                                }
                                else if (previousDirection == RIGHT)
                                    curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
                                    else {
                                        previousDirection = RIGHT;
                                        curAutoSpeed = 1;
                                    }
                                //Turn right
                                if ((curAutoSpeed % 5) == 0) { //Delay the string
                                    sprintf(DBGString, "Turn LEFT: %d\r", curAutoSpeed);    //wrong string due to an error
                                    SerialTransfer.SendDisplayString((char*)DBGString,0);
                                    DBGString[0] = '\0';
                                }

                                autoTurnRight();
                                delay(50);      //Slow down to delay cicles
                            }
                            else if (balancelForward == 0) {
                                SerialTransfer.isBack = false;

                            if (previousDirection == 99) {
                                previousDirection = FORWARD;
                                curAutoSpeed = 1;
                            }
                            else if (previousDirection == FORWARD)
                            curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
                                else {
                                previousDirection = FORWARD;
                                curAutoSpeed = 1;
                                }
                            if ((curAutoSpeed % 5) == 0) { //Delay the string
                                sprintf(DBGString, "Go FORWARD: %d\r", curAutoSpeed);
                                SerialTransfer.SendDisplayString((char*)DBGString,0);
                                DBGString[0] = '\0';
                            }
                            autoGoForward();
                            delay(50);      //Slow down to delay cicles
                            }
                            else if (balancelBackward == 0) {

                                SerialTransfer.isBack = true;
                                if (previousDirection == 99) {
                                    previousDirection = BACKWORD;
                                    curAutoSpeed = 1;
                                }
                                else if (previousDirection == BACKWORD)
                                    curAutoSpeed = curAutoSpeed + SPEEDINCREMENT;
                                    else {
                                        previousDirection = BACKWORD;
                                        curAutoSpeed = 1;
                                    }
                                if ((curAutoSpeed % 5) == 0) { //Delay the string
                                    sprintf(DBGString, "Go BACKWORD: %d\r", curAutoSpeed);
                                    SerialTransfer.SendDisplayString((char*)DBGString,0);
                                    DBGString[0] = '\0';
                                }
                                //go backward
                                autoGoBackward();
                                delay(50);      //Slow down to delay cicles
                            }
                            else
                            {

                            if (curAutoSpeed > 0) {
                                delay(50);
		                        curAutoSpeed-=2;
		                        switch (previousDirection){
		                        case FORWARD:
		                        autoGoForward();
		                        break;
		                        case BACKWORD:
		                        autoGoBackward();
		                        break;
		                        case LEFT:
		                        autoTurnLeft();
		                        break;
		                        case RIGHT:
		                        autoTurnRight();
		                        break;

                            }


                        }
                        else
                        {
                            previousDirection = 99;
                        }

 
                    

in the follwoing code you will see how to access the sabertooth library using very simple functions. A copy of the sabertooth library can be found in the Download area of this site

Sabertooth serial protocoll


                            //This is the declaration of the Sabertooth object. SWSerial is the serial port used. 
                            //In my case I am using the wire lib to create a virtual
                            //Serial port using a separate pin on the Arduino board
                            
                            Sabertooth ST(128, SWSerial);

                            //This function must be used at the beginning of your code to initialise the serial communication
                            //The serial communication can be obtained using the "wire" library or using a direct serial connection

                            void initSabertooth (void)  {  
  
                                SWSerial.begin(9600);  
                                ST.autobaud();
  
                            }

                            //In the stup function I strongly suggest to stop all motors using these commands
                            
                            ST.motor(1, SABER_ALL_STOP);
                            ST.motor(2, SABER_ALL_STOP);

                            //This is an example of the turn right function
                            //Simply tell to the motor the speed that is from 0 to 128 for a forward speed
                            //and from -1 to -128 for a backuward speed
                            //Other functions can be obtained in the same way

                            void autoTurnRight()   {
	
                                	ST.motor(1, curAutoSpeed);
	                                ST.motor(2, curAutoSpeed - (curAutoSpeed * 2));

                            }
                        

Leave a Comment