LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Autonomous car using Linx toolkit

Guys, iv built an obstacle avoidance robot car, it's 4wd and uses an ultrasonic sensor for detection.


I am looking at putting control from labview onto it in the form of the linx toolkit. It will be wired for now with he view of making it wireless eventually.

 

I am struggling with the event structure wiring within a while loop, especially the toggle switch on my block diagram( Boolean TF) I'm using to switch between autonomous mode and manual control from labview.

I need 6 event structures in total, F for forward, B for Backward, L for left, R for right, S for stop, A for autonomous and M for manual. 
Coud some one help me wire this, I'm only learning In labview and Linx I'm finding very difficult.

Any help appreciated.

Thank you

0 Kudos
Message 1 of 6
(812 Views)

Are you using the LINX toolkit with Arduino or RaspberryPi? What have you tried so far? Can you post your code?

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 6
(767 Views)

Hi I'm using arduino, il post the code when home! I have the arduino programmed and working perfectly that with serial monitor on the arduino it will do all the commands mentioned above F and B etc, I have the Auto manual command (A+M) toggling too! It's just the labview aspect that has me scratching my head 

0 Kudos
Message 3 of 6
(758 Views)

And yea, I'm trying to use the Linx toolkit but cannot find much help in terms of wiring it, especially event structures etc.

thanks

0 Kudos
Message 4 of 6
(757 Views)
#include <AFMotor.h>
#include <Servo.h>
#include <NewPing.h>

#define TRIG_PIN A0
#define ECHO_PIN A1
#define MAX_DISTANCE 300
#define MAX_SPEED 160
#define COLL_DIST 30

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor leftMotor1(1, MOTOR12_1KHZ);
AF_DCMotor leftMotor2(2, MOTOR12_1KHZ);
AF_DCMotor rightMotor1(3, MOTOR34_1KHZ);
AF_DCMotor rightMotor2(4, MOTOR34_1KHZ);
Servo myservo;

bool autoMode = false;

void setup() {
    Serial.begin(9600);
    myservo.attach(10);
    myservo.write(90);
    delay(1000);
}

void loop() {
    // Constantly check for commands, even in auto mode
    if (Serial.available()) {
        char command = Serial.read();
        Serial.print("Received: ");
        Serial.println(command);
        switch (command) {
            case 'F':
                if (!autoMode) moveForward();
                break;
            case 'B':
                if (!autoMode) moveBackward();
                break;
            case 'L':
                if (!autoMode) turnLeft();
                break;
            case 'R':
                if (!autoMode) turnRight();
                break;
            case 'S':
                if (!autoMode) moveStop();
                break;
            case 'A':
                autoMode = true;
                Serial.println("Switched to Auto Mode");
                break;
            case 'M':
                autoMode = false;
                Serial.println("Switched to Manual Mode");
                moveStop();
                return;
        }
    }
   
    if (autoMode) {
        int distance = readPing();
        if (distance < COLL_DIST) {
            Serial.println("Obstacle detected. Avoiding...");
            moveBackward();
            delay(500);
            turnLeft();
            delay(500);
        } else {
            moveForward();
        }
    }
}

int readPing() {
    delay(70);
    unsigned int uS = sonar.ping();
    int cm = uS / US_ROUNDTRIP_CM;
    return cm;
}

void moveStop() {
    leftMotor1.run(RELEASE);
    leftMotor2.run(RELEASE);
    rightMotor1.run(RELEASE);
    rightMotor2.run(RELEASE);
}

void moveForward() {
    leftMotor1.run(FORWARD);
    leftMotor2.run(FORWARD);
    rightMotor1.run(FORWARD);
    rightMotor2.run(FORWARD);
    leftMotor1.setSpeed(MAX_SPEED);
    leftMotor2.setSpeed(MAX_SPEED);
    rightMotor1.setSpeed(MAX_SPEED);
    rightMotor2.setSpeed(MAX_SPEED);
}

void moveBackward() {
    leftMotor1.run(BACKWARD);
    leftMotor2.run(BACKWARD);
    rightMotor1.run(BACKWARD);
    rightMotor2.run(BACKWARD);
    leftMotor1.setSpeed(MAX_SPEED);
    leftMotor2.setSpeed(MAX_SPEED);
    rightMotor1.setSpeed(MAX_SPEED);
    rightMotor2.setSpeed(MAX_SPEED);
}

void turnRight() {
    leftMotor1.run(FORWARD);
    leftMotor2.run(FORWARD);
    rightMotor1.run(BACKWARD);
    rightMotor2.run(BACKWARD);
    leftMotor1.setSpeed(MAX_SPEED);
    leftMotor2.setSpeed(MAX_SPEED);
    rightMotor1.setSpeed(MAX_SPEED);
    rightMotor2.setSpeed(MAX_SPEED);
}

void turnLeft() {
    leftMotor1.run(BACKWARD);
    leftMotor2.run(BACKWARD);
    rightMotor1.run(FORWARD);
    rightMotor2.run(FORWARD);
    leftMotor1.setSpeed(MAX_SPEED);
    leftMotor2.setSpeed(MAX_SPEED);
    rightMotor1.setSpeed(MAX_SPEED);
    rightMotor2.setSpeed(MAX_SPEED);
}
0 Kudos
Message 5 of 6
(720 Views)

What did you have in mind for your User Interface?  Your Linx code uses single character strings for all the commands -- do you intend to "drive your car" by typing specific letters on a keyboard?  

 

All of your commands are "binary" in nature -- "Go" (at max speed) or "Stop" (instantaneous 0 velocity).  "Right" means "spin to the right by turning the left wheels forward at max speed and the right wheels backward at max speed" -- again, all or nothing, and car linear velocity goes from "whatever" (when driving straight ahead) to 0 (when turning) -- not good for the tires!  How about a rotary control that "turns the front wheels" slightly?

 

Most of the time, your car is running along, "doing the same thing".  Every so often, you change something on the Front Panel (what?  a String input?  a Boolean Button? a Numeric Dial?) to "give the car another command" (which it should do "instantaneously".  Do you know about LabVIEW's Event Structures, which are used to "fire" LabVIEW code when a Front Panel Control is changed?

 

So it depends how you want to handle "Events".  In the example of the Linx code you posted, when you get a command, you simply issue commands to motors (and other things).  I notice that you often follow the command by a Delay(), which suggests that a "time parameter" might be "designed" (by you) into your command structure.

 

LabVIEW, with its "interactive Front Panel" for simulating "real controls" (such as a rotary "Steering Wheel", a linear "Accelerator" and "Brake", and modeling Actuators (motors attached to wheels, possibly actuators to "turn the front wheels up to ±30°".  You can also write little sub-VIs with names like "Accelerate" (which gradually increases the speed that the wheels turn) or "Turn" (which takes an angle for the turn).  Encapsulating the "messy details" in a sub-VI, particularly if you design it with an icon that says (or "shows", by means of an image) what the VI does, makes it possible to fit an entire Control Program for your car on a single Laptop Screen (of course, it will have multiple "layers", like a State Machine ...).

 

Bob Schor

 

0 Kudos
Message 6 of 6
(705 Views)