ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

// Mixed Mode Sample for Kangaroo
// Copyright (c) 2013 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>
#include <Kangaroo.h>

// Arduino TX (pin 11) goes to Kangaroo S1
// Arduino RX (pin 10) goes to Kangaroo S2
// Arduino GND         goes to Kangaroo 0V
 // Arduino 5V          goes to Kangaroo 5V (OPTIONAL, if you want Kangaroo to power the Arduino)
 #define TX_PIN 2 //s1
 #define RX_PIN 3 //s2

 // Mixed mode channels on Kangaroo are, by default, 'D' and 'T'.
 SoftwareSerial  SerialPort(RX_PIN, TX_PIN);
 KangarooSerial  K(SerialPort);
 KangarooChannel Drive(K, 'D');
 KangarooChannel Turn(K, 'T');

 void setup()
 {
  SerialPort.begin(9600);
  SerialPort.listen();
  Serial.begin(9600);

  Drive.start();
  Turn.start();

  Drive.si(0);
  Turn.si(0);
  Serial.println("Started...");
  SerialPort.println("D, units 100 thou = 256 lines");
  SerialPort.println("T, units 100 thou = 256 lines");

  }

  void loop()
  {
   //  Drive 500 ticks (relative to where we are right now), then wait 1 second.
   //Drive.pi(500).wait();
   //delay(1000);

   // Turn 500 ticks (relative to where we are right now), then wait 1 second.
    //Turn.pi(500).wait();  
   //delay(1000);
   if (SerialPort.available()) {
    Serial.write(SerialPort.read());

     }
   if (Serial.available()) {
     SerialPort.write(Serial.read());
    } 
  }

Connect an Arduino as per the code

// Mixed Mode Sample for Kangaroo
// Copyright (c) 2013 Dimension Engineering LLC
// See license.txt for license details.

#include <SoftwareSerial.h>
#include <Kangaroo.h>

// Arduino TX (pin 11) goes to Kangaroo S1
// Arduino RX (pin 10) goes to Kangaroo S2
// Arduino GND         goes to Kangaroo 0V
 // Arduino 5V          goes to Kangaroo 5V (OPTIONAL, if you want Kangaroo to power the Arduino)
 #define TX_PIN 2 //s1
 #define RX_PIN 3 //s2

 // Mixed mode channels on Kangaroo are, by default, 'D' and 'T'.
 SoftwareSerial  SerialPort(RX_PIN, TX_PIN);
 KangarooSerial  K(SerialPort);
 KangarooChannel Drive(K, 'D');
 KangarooChannel Turn(K, 'T');

 void setup()
 {
  SerialPort.begin(9600);
  SerialPort.listen();
  Serial.begin(9600);

  Drive.start();
  Turn.start();

  Drive.si(0);
  Turn.si(0);
  Serial.println("Started...");
  SerialPort.println("D, units 100 thou = 256 lines");
  SerialPort.println("T, units 100 thou = 256 lines");

  }

  void loop()
  {
   //  Drive 500 ticks (relative to where we are right now), then wait 1 second.
   //Drive.pi(500).wait();
   //delay(1000);

   // Turn 500 ticks (relative to where we are right now), then wait 1 second.
    //Turn.pi(500).wait();  
   //delay(1000);
   if (SerialPort.available()) {
    Serial.write(SerialPort.read());

     }
   if (Serial.available()) {
     SerialPort.write(Serial.read());
    } 
  }

This is the Python Script which will talk to the Arduino

  from time import sleep
  import serial
  ser = serial.Serial('/dev/ttyUSB1', 9600) # Establish the connection on a speci$
  counter = 32 # Below 32 everything in ASCII is gibberish
  ser.write("D,home")
  ser.write("T,home")
  while True:
     counter +=10
     ser.write("T,p"+str(counter)) # Convert the decimal number to ASCII then s$
     print ser.readline() # Read the newest output from the Arduino
     sleep(.1) # Delay for one tenth of a second
     if counter == 255:
        counter = 32