Categories
Python Robotics ROS

TensorFlow / Keras Model Predict Error

Unexpected error: Tensor Tensor("dense_1/BiasAdd:0", shape=(?, 3), dtype=float32) is not an element of this graph.

To Fix:

Make sure to include the following global:

import tensorflow as tf

global graph,model
graph = tf.get_default_graph()

And surround the prediction as such:

with graph.as_default():
                segment = self.model.predict(features)
Categories
HowTo Programming

Microchip MPLAB X – Link Error: region is full / section overlaps section

While trying to compile some code on MPLAB X I came across this link error, stating that my #pragma config bits were full or sections of them were overlapping other sections.

/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FOSC is full (dist/default/production/can_to_serial.production.elf section __FOSC)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FWDT is full (dist/default/production/can_to_serial.production.elf section __FWDT)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: region FBORPOR is full (dist/default/production/can_to_serial.production.elf section __FBORPOR)
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: section .config_MCLRE%10 [f80004   -> f80005  ] overlaps section __FWDT [f80004   -> f80005  ]
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link Error: section .config_WDT%11 [f80002   -> f80003  ] overlaps section __FOSC [f80002   -> f80003  ]
/Applications/microchip/xc16/v1.11/bin/bin/../bin/elf-ld: Link terminated due to previous error(s).
make[2]: *** [dist/default/production/can_to_serial.production.hex] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

After some time scratching my head I realised the issue was that configuration bits were being set twice. Simply I had to remove them. I also moved all configuration bits to a separate header which is only included in the main c source file to avoid future issues.

Code causing the error:

main.c
#include 
#include 
#include 

// FOSC
#pragma config FPR = XT_PLL4            // Primary Oscillator Mode (XT w/PLL 4x)
#pragma config FOS = PRI                // Oscillator Source (Primary Oscillator)
#pragma config FCKSMEN = CSW_FSCM_OFF   // Clock Switching and Monitor (Sw Disabled, Mon Disabled)

// FWDT
#pragma config FWPSB = WDTPSB_16        // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF            // Watchdog Timer (Disabled)

// FBORPOR
#pragma config FPWRT = PWRT_64          // POR Timer Value (64ms)
#pragma config BODENV = BORV20          // Brown Out Voltage (Reserved)
#pragma config BOREN = PBOR_ON          // PBOR Enable (Enabled)
#pragma config LPOL = PWMxL_ACT_HI      // Low-side PWM Output Polarity (Active High)
#pragma config HPOL = PWMxH_ACT_HI      // High-side PWM Output Polarity (Active High)
#pragma config PWMPIN = RST_IOPIN       // PWM Output Pin Reset (Control with PORT/TRIS regs)
#pragma config MCLRE = MCLR_DIS         // Master Clear Enable (Disabled)

// FGS
#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF      // General Segment Code Protection (Disabled)

// FICD
#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)

// Configuration settings
_FOSC(CSW_FSCM_OFF & FRC_PLL16); // Fosc=16x7.5MHz, Fcy=30MHz
_FWDT(WDT_OFF);                  // Watchdog timer off
_FBORPOR(MCLR_DIS);              // Disable reset pin

int main(){
// ... code continues here

Altered code:

main.c
#include 
#include 
#include "config.h"
#include 

int main(){
// ... code continues here
config.h
// FOSC
#pragma config FPR = XT_PLL4            // Primary Oscillator Mode (XT w/PLL 4x)
#pragma config FOS = PRI                // Oscillator Source (Primary Oscillator)
#pragma config FCKSMEN = CSW_FSCM_OFF   // Clock Switching and Monitor (Sw Disabled, Mon Disabled)

// FWDT
#pragma config FWPSB = WDTPSB_16        // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF            // Watchdog Timer (Disabled)

// FBORPOR
#pragma config FPWRT = PWRT_64          // POR Timer Value (64ms)
#pragma config BODENV = BORV20          // Brown Out Voltage (Reserved)
#pragma config BOREN = PBOR_ON          // PBOR Enable (Enabled)
#pragma config LPOL = PWMxL_ACT_HI      // Low-side PWM Output Polarity (Active High)
#pragma config HPOL = PWMxH_ACT_HI      // High-side PWM Output Polarity (Active High)
#pragma config PWMPIN = RST_IOPIN       // PWM Output Pin Reset (Control with PORT/TRIS regs)
#pragma config MCLRE = MCLR_DIS         // Master Clear Enable (Disabled)

// FGS
#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF      // General Segment Code Protection (Disabled)

// FICD
#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
Categories
C/C++ Command Line Linux Programming Ubuntu

fatal error: curl/curl.h: No such file or directory | Ubuntu 12.04

fatal error: curl/curl.h: No such file or directory

If you’re missing the curl/curl.h header file, chances are you’re just missing the correct dev package file for the curl library.

sudo apt-get install libcurl4-gnutls-dev

That should fix it.

Categories
Posts Programming ROS

ROS – rviz X Window System error.

rosrun rviz rviz
[ INFO] [1322561467.803234807]: rviz revision number 1.6.7
[ INFO] [1322561467.803351442]: ogre_tools revision number 1.6.2
[ INFO] [1322561467.803374070]: compiled against OGRE version 1.7.3 (Cthugha)
[ INFO] [1322561467.946771146]: Loading general config from [/home/alex/.rviz/config]
[ INFO] [1322561467.946953292]: Loading display config from [/home/alex/.rviz/display_config]
[ INFO] [1322561467.972674791]: RTT Preferred Mode is PBuffer.
The program 'rviz' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadDrawable (invalid Pixmap or Window parameter)'.
  (Details: serial 22 error_code 9 request_code 137 minor_code 3)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

I got this error when I incorrectly compiled rviz using:

rosmake rviz rviz

You’ll want to re-compile it correctly, with only 1 input as followed:

rosmake rviz

Now when you run it, everything should be working.

Categories
Blog Posts Programming Python

Python – Making Use of Google’s Text To Speech Translation Tool

Text to speech (tts) is a difficult task to get right and there are quite a few packages that show just how hard with their terrible tinny voices, these are also usually only limited to English, which for the larger part than most people would like to believe don’t find it very useful. Nevermind, Google to the rescue, their Translation tool has had the ability to also voice translations for a while now. So wouldn’t it be awesome if we could utilize this, stable, constantly developing and ultimately free utlilty? Yes? Well luckly for you it’s possible. It’s been done before with the use of JavaScript, like here but those more used to scripting and desktop programming don’t worry, you can use it too.

Basically it works by sending a request to the Google translate servers which then, pretty much instantly, reply with an MP3 file which contains the requested words in their most sexy of robot voices.

Check this URL for an example of said voice – http://translate.google.com/translate_tts?q=check+out+my+sexy+robot+voice (if it doesn’t load in your browser, open VLC, CTRL+N and paste the URL in)

First, we want to be able to get python to stream an MP3 file off the web:

More info on this can be found here, the following code was is a stripped down version of the code found at codeboje.de.

[gist][/gist]

Now we want to make a string to send :

We’re going to use command line arguments as the string which wants to be read by the Google TTS engine, the following code will grab those arguments and concatenate them into a string. It also has to be in a format like a usual Google URL, these usually replace white space for the ‘+’ sign, that’s easy to do.

[gist][/gist]

Now let’s just pass this URL to the bit we wrote to stream an MP3 and watch it go:

Full Source Code:

(Uses command line arguments as it’s input, run like ‘python ttsString.py Hello World‘)
[gist][/gist]

That’s pretty much how easy it is to use Google’s free online TTS engine, one main thing to watch out for is the 100 character limit to the use of this service in this way along with the API call limits which apply to each IP address. There are loads of cool things this can be used for and I’d love to see what anyone comes up with, keep me posted and have fun!

Categories
Blog Posts Programming Python

Python – Writing a ‘Fuzzy Clock’

If you want a clock that’s a little more human, there’s no better way than a ‘Fuzzy’ clock, essentially this converts the time in to a more brain friendly format such as “Twenty past Twelve” rather than 12:22.

Writing a simple fuzzy clock
Source Code:

[gist][/gist]

Output:

$ python fuzzytime.py
It’s 25 to 2

Writing a more readable fuzzy clock:

Now, this returns in a form of “It’s 20 past 1” rather than “It’s twenty past one”, if you’re going to want this then it’s only a little more tricky. For this I used a lookup table which would essentially replace the numbers for the written numbers.

Source Code:

[gist][/gist]

Output:

$ python fuzzytime.py
It’s two o’clock

Categories
C/C++ Linux Posts Programming Robotics ROS

ROS: Publishing and Subscribing to Arrays

In ROS (Robot Operating System) it’s really easy to publish variables to be used between nodes running on the same roscore however I was having some difficulty doing the same for arrays. The problem came when there was no real examples of how to use them, so here is a working example of std_msgs/*MultiArray in CPP.

Publishing:

[gist][/gist]

Subscribing:

[gist][/gist]

Categories
Fedora Linux Posts Programming

GitHub: Agent admitted failure to sign using the key.

Upon testing my GitHub setup on my home computer I got the following error after inputting this:

ssh git@github.com

Returned:

Agent admitted failure to sign using the key.
Permission denied (publickey).

You’ll need to run:

ssh-add ~/.ssh/id_rsa

Make sure to enter the passphrase for the ssh key you generated.

Categories
Blog Kinect Machine Vision Posts Programming Robotics

Kinect Development – Day 1

Head over to this page if you want some tutorials on getting started with the Kinect and libfreenect, I’ll update more as time goes on and I have free time.

I’ve been meaning to grab myself an Xbox 360 Kinect for a while, not because I’m a big motion controlled game fan but for machine vision development. Within the first month of the Kinect open source drivers being released the coolest things were seen, from motion controlled media centres to 3D modelling. I’ll admit, I’m a little late to the game, mostly due to the amount of work in my final year at university and other general business. Over the summer I’ll have plenty of time to do a couple of projects and hopefully come up with something cool and contribute to the scene.

Anyway enough of the small talk, I’ve decided to blog in as much detail the journey through the development, from the installation of the libraries to writing the first and last bit of code as a sort of a set of tutorials for anyone else who wants to get into it.

There are currently two main sets of drivers/libraries out there libfreenect and OpenNI both sporting hip, cool, open source names. So which one do you choose? Well, here’s a brief description of both.

Let’s start with OpenNI, these are the Official PrimeSense (the people that Microsoft paid to actually create the Kinect) these allow access to audio, video and depth with the addition of PrimeSense’s NITE Middleware. NITE is the software library used for skeletal tracking, hand gesture recognition and scene analyzer (used to separate figures in the foreground from the background) .

Alternatively there is the libfreenect libraries, from the community over at openkinect.org. While these are admittedly lacking slightly in features such as skeletal tracking and hand gesture recognition they much make up for it in the dedication to open source and the creation of the best suite available. These have access to video, microphones, motors and LED with speakers currently being worked on. They work under a variety of language wrappers for most OS’s and will of course by my personal library of choice.

Fortunately, you won’t have to decide which one you’d prefer ’cause you can run them both on the same machine but you’ll have to look into licencing information for releasing projects with OpenNI so it’s unlikely you’ll want to combine them (or even allowed?).

libfreenect Installation:

OpenKinect’s getting started page provides a well enough documented installation guide that anyone should be able to get them up and running under Windows/Linux or OSX. With Ubuntu being the distro of choice for installation guide. – http://openkinect.org/wiki/Getting_Started

If you’re running Arch, there are a few AUR packages available however they all seem to have lacked updates for a few months but the manual build is pretty simple on the getting started page, I’ve also added a quick list of commands to get you there:

Grab the git copy of the libraries:

git clone https://github.com/OpenKinect/libfreenect.git
cd libfreenect/

Make, install:

mkdir build
cd build/
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib64/

Add your user to allow access to the connect by creating a group called video and adding your user to it:
note: this can be skipped if you don’t mind running as root/sudo

sudo nano /etc/udev/rules.d/66-kinect.rules
sudo usermod -G video username

Test the kinect with the example program:

bin/glview

If all went well you should have seen a sight similar to the screenshot above, if not check out the OpenKinect page for more information and see if the problems you’re having haven’t already been resolved.

Categories
Linux Posts Python Ubuntu

ImportError: No module named …

Numeric

Error:

Traceback (most recent call last):
  File "", line 1, in
ImportError: No module named Numeric

Package:

sudo apt-get install python-numeric

ImageTk

Error:

ITraceback (most recent call last):
  File "", line 1, in
ImportError: No module named ImageTk

Package:

sudo apt-get install python-imaging-tk