• 0
M

SRK line not working

Question

Good Day

I have recently acquired the SRK robot. I have managed to make the basic program work using Mpide (SRK Basic i.e. the one that manually navigates the robot depending which button is pressed). However I am struggling to make the robot follow a line using the code from the Digilent website (SRK Line). I have adjusted the yellow know to adjust the sensitivity. I notice the sensors are not very accurate, the LEDs are illuminated even though I have placed it on a a black line. I have tried different lighting with no success in making the robot follow a line. When I press BTN2 it moves for a millisecond then stops and a green LED on the MX3CK board blinks green for a few times. Is there any other software that might assist or is it perhaps a hardware problem. Please advise. Greatly appreciated.

Edited by Josh
Added Tags

Share this post


Link to post
Share on other sites

18 answers to this question

Recommended Posts

  • 1

Hi M,

I apologize for not getting back to you over the weekend.

In terms of the right servo moving faster than the left servo you can do one of two things. Inside the code for MPIDE, there are the three functions that move the robot: Foward(), TurnRight(), and TurnLeft(). Inside each of those functions you can either choose to slow down the right servo by providing the right.write() function inside each of them with a smaller number. Or you may change the value in the left.write() functions to a larger number. In other words, to make the robot go perfectly straight it will be a matter of trial and error since the default values will inevitably not work for every servo motor.

As for your two outer sensors not responding; I would be inclined to think that the sensors themselves would be more like experiencing the problem as opposed to the PmodLS1, but without testing them both, it's hard to know which component is at fault. 

In terms of response times, I'm not seeing any way to make the response faster in software -- the biggest thing that I can think of, which you already did, would be to replace the batteries. All of the robots, especially the line following ones, will deteriorate in performance as the batteries get used up. You could also adjust the algorithm that turns the robot right or left by excluding all of the external sensor values (1, 3, 7, 8, 12, and 14), but I do not think this would improve the performance.

Please let me know if I forgot to address something.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 1

Hi,

For your first video with you plugging in the last battery and seeing the motors jerk for a brief moment and then having a green LED blink several times, that is the chipKIT MX3 performing its internal bootup sequence so the microcontroller chip operates correctly. The motors jerk because they suddenly receive some power; this is the expected behavior of the board.

As for your second video, it is a little weird that the robot does not start when you initially place it on the black line and that it completely stops when the far left sensor "hits" the black line between the tiles. The third time that the robot stops though is because all four sensors are noticing the black caulk line on your tile floor.

Based on this, I have two recommendations. The first is to try adjusting the sensitivity of the PmodLS1 again. What I did was turn the robot upside down so that its sensors were facing the ceiling and rotated the knob until just before the LEDs on the PmodLS1 turned on. I put a photo in the gallery of where my knob was rotated to.

The second recommendation is to replace part of the code that tells the robot to turn left or right with new code (mostly because I thought the old code wasn't written very well).

Replace this code in the loop function:

if(bInstruction == 3 || bInstruction == 7 || bInstruction == 11 || bInstruction == 1 || bInstruction == 5){
      TurnRight();
    }
    else if(bInstruction == 12 || bInstruction == 13 || bInstruction == 14 || bInstruction == 8 || bInstruction == 10) {
      TurnLeft();
    }

With this set of code instead:

if(bInstruction == 1 || bInstruction == 2 || bInstruction == 3 || bInstruction == 7){
      TurnRight();
    }
    else if(bInstruction == 8 || bInstruction == 4 || bInstruction == 12 || bInstruction == 14){
      TurnLeft();
    }

This made the SRK robot that I was testing work a little more efficiently (at least in my opinion).

Let me know how it goes!

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Hi M,

What you're describing when you press BTN2 and then having the MX3CK board blinking a green LED is indicative that there is an electrical short somewhere with the servo motors, causing the MX3CK to use its shut-down circuitry. It does seem a little weird that even when you adjust the knob for the PmodLS1 that the sensors still light up even on a dark surface, although this is unrelated to the short.

Could you post a picture(s) of your setup so I can take a look at it? You can use our Gallery or some other way to post/host the photo.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Thank you for your time and patience. I have posted my images under the gallery. Hopefully you can diagnose the problem.

https://forum.digilentinc.com/gallery/category/2-support-galleries/

This is the code I have been using. It is the reference version from the website:

/************************************************************************/
/*                                                */
/*    SRK_Line                                           */
/*                                              */
/*                                                */
/************************************************************************/
/*    Author: Jordan Retz                        */
/*    Copyright 2012, Digilent Inc.                    */
/************************************************************************/
/*  Module Description:                                  */
/*                                                */
/* This module implements a simple demo application that shows how to   */
/* program the RDK Line - Servo.                                        */
/*                                    */
/*    Functionality:                            */
/*                                    */
/* The application uses the PmodLS1, four IR proximity sensors, and two */
/* servo motors. Based on the outputs of the four sensors attached to   */
/* the Pmod, the robot will alter it's direction to stay on a line.     */
/* The robot will work best if the line is black electric tape on a     */
/* white surface.                                                       */
/*                                                                      */
/* The sensors are referred to as Far Right (FRS), Mid Right (MRS), Mid */
/* Left (MLS), and Far Left (FLS). These should be connected to S1, S2, */
/* S3, S4, respectively, on the PmodLS1. Left and right are determined  */
/* looking down on robot with sensor, bracket forward.                  */
/*                                                                      */
/*                                                                      */
/*      Instruction     FRS MRS MLS FLS    Function                     */
/*          0            0   0   0   0     Stop                         */
/*          1            0   0   0   1     Turn Right                   */
/*          2            0   0   1   0     Continue                     */
/*          3            0   0   1   1     Turn Right                   */
/*          4            0   1   0   0     Continue                     */
/*          5            0   1   0   1     Turn Right                   */
/*          6            0   1   1   0     Continue                     */
/*          7            0   1   1   1     Turn Right                   */
/*          8            1   0   0   0     Turn Left                    */
/*          9            1   0   0   1     Continue                     */
/*          10           1   0   1   0     Turn Left                    */
/*          11           1   0   1   1     Turn Right                   */
/*          12           1   1   0   0     Turn Left                    */
/*          13           1   1   0   1     Turn Left                    */
/*          14           1   1   1   0     Turn Left                    */
/*          15           1   1   1   1     Move Foward                  */
/*                                                                      */
/* Pressing BTN2 on the PmodBTN will Start or Stop the robot. The       */
/* PmodBTN must be connected to the top row of JD. The PmodCON3 must    */
/* be connected to the bottom row of header JC. The PmodLS1 must be     */
/* connected to the bottom row of JB. Only BTN2 is a valid input.          */
/*                                                                      */
/*     Programming:                                                     */
/*                                                                      */
/* Make sure that the MX3cK is plugged into the computer via USB cable, */
/* and that the board is powered.                                       */
/*                                                                      */
/* From the toolbar above, select "Tools->Board->MX3cK". From the Start */
/* menu, navitgate to "Start->Control Panel->Hardware and Sound->Device */
/* Manager". Select "Ports", and take note of what COM port (COMx) is   */
/* labeled "USB Serial Port". If you are unsure, unplug the MX3cK from  */
/* the computer and watch which COM port disappears, and then           */
/* reappears, when you plug the MX3cK back into the computer.           */
/* From the toolbar above, select "Tools->Serial Port" and then the COM */
/* port that you just found. Apply power to the MX3cK and click on the  */
/* "Upload" button above.                                               */
/*                                                                      */
/************************************************************************/
/*  Revision History:                                */
/*                                                */
/*    6/21/2012 (JordanR): created                           */
/*  12/17/2012 (MichaelK): Name Change
/*                                                 */
/************************************************************************/

/* ------------------------------------------------------------ */
/*                Include File Definitions                      */
/* ------------------------------------------------------------ */
#include <plib.h>
#include <Servo.h>

/* ------------------------------------------------------------ */
/*                Local Type Definitions        */
/* ------------------------------------------------------------ */
/* These definitions are valid if the PmodCON3 is connected to the
** bottom row of header JC
*/
#define    pinServoLeft   23
#define    pinServoRight  22

/* These definitions are valid if the PmodBTN is connected to the
** top row of header JD
*/
#define    pinBTN0        24
#define    pinBTN1        25
#define    pinBTN2        26
#define    pinBTN3        27

/* These definitions are valid if the PmodLS1 is connected to the
** bottom row of header JB
*/
#define    pinFarRight    12
#define    pinMidRight    13
#define    pinMidLeft     14
#define    pinFarLeft     15


/* ------------------------------------------------------------ */
/*                Global Variables                              */
/* ------------------------------------------------------------ */
/*Define Servos*/
Servo      left;
Servo      right;

byte       bInstruction;
byte       bPrevInstruction;
bool       fRobotStartStop;

/* ------------------------------------------------------------ */
/*                Forward Declarations                          */
/* ------------------------------------------------------------ */

void CheckSensors();
void StopRobot();
void Forward();
void TurnRight();
void TurnLeft();
void RobotStartStop();

/* ------------------------------------------------------------ */
/*                Procedure Definitions                         */
/* ------------------------------------------------------------ */
/***  void setup()
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**    Initialize the system.
*/
void setup() {
  /*Setup Input/Output on Pins
  */
  pinMode(pinServoLeft, OUTPUT);
  pinMode(pinServoRight, OUTPUT);
  
  pinMode(pinBTN0, INPUT);
  pinMode(pinBTN1, INPUT);
  pinMode(pinBTN2, INPUT);
  pinMode(pinBTN3, INPUT);
  
  pinMode(pinFarRight, INPUT);
  pinMode(pinMidRight, INPUT);
  pinMode(pinMidLeft, INPUT);
  pinMode(pinFarLeft, INPUT);
  
  /*Set Robot default state to STOPPED
  */
  fRobotStartStop = false;
  
  /*Attach External Interrupt EXT_INT3
  */
  attachInterrupt(EXT_INT3, ISRRobotStartStop, RISING);
 
}

/* ------------------------------------------------------------ */
/***  void loop();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**    Main application loop.
*/
void loop()
{
  CheckSensors();
  
  /* Robot Stop if all Sensors are off OR if fRobotStartStop == false
  */
  if(bInstruction == 0 || fRobotStartStop == false) {
    StopRobot();
  }
  
  /* Robot Start if at least one Sensor is on AND if fRobotStartStop == true
  */
  else if(fRobotStartStop == true) {
    
    if(bInstruction == 3 || bInstruction == 7 || bInstruction == 11 || bInstruction == 1 || bInstruction == 5){
      TurnRight();
    }
    else if(bInstruction == 12 || bInstruction == 13 || bInstruction == 14 || bInstruction == 8 || bInstruction == 10) {
      TurnLeft();
    }
    else {
      Forward();
    }
  }
}


/* ------------------------------------------------------------ */
/***  byte CheckSensors();
**
**  Parameters:
**    none
**
**  Return Value:
**  none
**
**  Errors:
**  none
**
**  Description:
**    Returns the state of the sensors. Must be connected to JA
*/
void CheckSensors() { 
  
    byte bFRS = digitalRead(pinFarRight)*(0x8);
    byte bMRS = digitalRead(pinMidRight)*(0x4);
    byte bMLS = digitalRead(pinMidLeft)*(0x2);
    byte bFLS = digitalRead(pinFarLeft)*(0x1);
  
    bInstruction = (bFRS | bMRS | bMLS | bFLS);
}

/* ------------------------------------------------------------ */
/***    void StopRobot();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**    Stops robot by finding Servo position and reducing or increasing to 90. 
**    Then detaches pins.
*/
void StopRobot() {  
  
  left.write(90);
  right.write(90);
  
  left.detach();
  right.detach(); 
}

/* ------------------------------------------------------------ */
/***    void Forward();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**    Moves robot forward
*/
void Forward() {
  
  left.attach(pinServoLeft);
  right.attach(pinServoRight);
  
  left.write(107);
  right.write(73);
}

/* ------------------------------------------------------------ */
/***    void turnRight();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**    Turns robot right
*/
void TurnRight() {
  
  left.attach(pinServoLeft);
  right.attach(pinServoRight);
  
  left.write(107);
  right.write(107);
}

/* ------------------------------------------------------------ */
/***    void turnLeft();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**   Turns robot left
*/
void TurnLeft() {
  
  left.attach(pinServoLeft);
  right.attach(pinServoRight);
  
  left.write(73);
  right.write(73);  
}

/* ------------------------------------------------------------ */
/***    void ISRRobotStartStop();
**
**  Parameters:
**    none
**
**  Return Value:
**    none
**
**  Errors:
**    none
**
**  Description:
**   External Interrupt Service Routine. When button is pressed,
**  checks the state of the robot (moving/stopped) and toggles it.
**  Robot will then move forward or stop accordingly.
*/
void ISRRobotStartStop() {
   /* This line of code toggles the value of fRobotStartStop
   */
   fRobotStartStop = !fRobotStartStop;
}

Share this post


Link to post
Share on other sites
  • 0

Hi M,

I checked out your photos and may (or may not) see your issue. It looks like everything is set up nicely and in the correct Pmod headers, but I want to double check on the placement. Is your PmodBTN plugged into the top row of JD and the PmodCON3 and PmodLS1 plugged into the bottom rows of both JC and JB, respectively? It looks like they are, but I want to double check. I also presume that you are pressing BTN2 on the PmodBTN as opposed to the reset button the MX3 (the reset button would also produce the described behavior).

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Yes. I have connected the cables as you have mentioned and pressing the BTN2. I have verified this by running the basic program which allows the robot to respond to different buttons being depressed either moving it forwrd, backwards, left or right, However the line follower does not work.  Could it be a faulty MX3CK board?

Share this post


Link to post
Share on other sites
  • 0

I have attached videos of the robot. Please advise if it is faulty so I can return it to the supplier. Thanks

Share this post


Link to post
Share on other sites
  • 0

I have adjusted the sensitivity and this has made a difference to the 2 sensors in the middle. However the outer sensors do not respond. I think the PMODSL is faulty. To overcome this I have removed the 2 outer sensors and modified the code so the robot does not sense them.

When testing the code the robot moves towards a black line, stops there and tries to follow the line. It follows the line very slowly with many stops in between. The robot also does not rotate both servos at the same speed. The right wheel moves faster than the left pulling the robot towards the right side.

Any suggestions on making it faster in its response time when following the line and how to synchronise the wheels to rotate at the same speed thus making it go perfectly straight.

 

Her are my modified sections of code:

//  pinMode(pinFarRight, INPUT);
  pinMode(pinMidRight, INPUT);
  pinMode(pinMidLeft, INPUT);
  //pinMode(pinFarLeft, INPUT);

 byte bMRS = digitalRead(pinMidRight)*(0x4);
 byte bMLS = digitalRead(pinMidLeft)*(0x2);  

I have left this unchanged

 if(bInstruction == 1 || bInstruction == 2 || bInstruction == 3 || bInstruction == 7){
      TurnRight();
    }
    else if(bInstruction == 8 || bInstruction == 4 || bInstruction == 12 || bInstruction == 14){
      TurnLeft();
    }
    else {
      Forward();
    }

Once again thank you for your patient responses.

Share this post


Link to post
Share on other sites
  • 0

I have used a thinner line, the same thickness as the caulk line on my tile floor so that the 2 sensors remain accurate

Share this post


Link to post
Share on other sites
  • 0

I am at another roadblock. The servo on the right side is causing the board to shut down. I have tried using the Basic program with no success.  I have modified it a bit to show you the problem.

I have set it to go in a square with the following code:

 Forward();
  delay(5000);
  TurnRight();  
  delay(1550);
  Forward();
  delay(5000);
  TurnRight();  
  delay(1550);
  Forward();
  delay(5000);
  TurnRight();  
  delay(1550);
  Forward();
  delay(3000);
  StopRobot();
 

When attaching one servo the robot moves, when attaching two, it stalls. Please advise as I am at my wits end. I wanted to make a simpler demo by disregarding the sensors and just making the robot go around a square as the robot started to freeze up after I sent yesterdays videos through.

I have attached a video to demonstrate the problem

Thanks

Share this post


Link to post
Share on other sites
  • 0

#define    pinServoLeft   21
#define    pinServoRight  20

 

I have attached the servo to the other two pins. The result is the same, the right servo "hangs" and does not complete the circle even if the left one is disconnected. The left servo does not have the same problem and makes a full circle when the right servo is disconnected. (using my code above)

Share this post


Link to post
Share on other sites
  • 0

I changed the batteries to a fresh set and that seems to have the solved the servo problem. However right servo moving faster than left. Pls advise

 

Thanks

Share this post


Link to post
Share on other sites
  • 0

No apologies necessary. I am grateful for your assistance. By manipulating the servo I have managed to achieve it proceeding in a straight line.

For my initial demo I made the robot follow a course which is sufficient for now. I will test the sensors more extensively at the end of the week. If you have any code or other ideas to test the sensors, please pass it on.

Once again Thanks

Share this post


Link to post
Share on other sites
  • 0

Hi M, 

I'm sorry for all the confusion you are having. 

I think I may know the problem you are having with the sensors based on the photos you posted. The distance between the right and left sensors has to be the same as the thickness of the line the robot is following. 

Follow this link to view my instructable on putting together the line follower. Note step 18, there is an image of proper sensor placement. 

Kaitlyn

Edited by KaitlynFranz

Share this post


Link to post
Share on other sites
  • 0

Hi again M, 

A good way to test to make sure the sensors are functioning properly is with a white and black piece of paper. The LEDs on the PmodLS1 indicate what signal the sensors are recieving. You can use this to debug the sensors operation as well as find the correct sensitivity. 

Kaitlyn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now