Wishful Coding

Didn't you ever wish your
computer understood you?

Pincer bot

I don’t exactly remember how I made the claw in the video earlier, but I’ve made a new one for you, so you can play with it.

The claw can be mounted on the front side of the Rover from the NXT 2.0

You can use this claw with the gamepad code from my previous post, but maybe you can mount the ultrasonic sensor and program it to fetch you a drink?

Download Building Instructions

Gamepad remote control

I had this pincer bot that I had not yet programmed, but using software remotes proved disappointing. With a few lines of code, I was able to use any gamepad or joystick to control the robot.

To use this code, you need to know how to execute commands on your computer. Then, do the following.

  1. Install Python if you don't already have it.
  2. Install PyGame for interfacing with the gamepad.
  3. Install NXT-python for interfacing with the NXT.
  4. Make sure your NXT and gamepad are connected and working.
  5. Run
    python nxtjoy.py
    in the directory where you've downloaded the code below.
The code assumes you have the pincer bot in the video, for which I'll give you instructions later. Moving around should work with most tank-steered robots.
import pygame
from nxt import locator, motor
from time import sleep

# edit this to reflect your joystick axis and buttons
axis = {'x':0, 'y':1}

b = locator.find_one_brick()

left = motor.Motor(b, motor.PORT_B)
right = motor.Motor(b, motor.PORT_A)
action = motor.Motor(b, motor.PORT_C)

closed = False

def limit(nr):
    if nr > 50 or nr < -50:
        return min(127, max(-128, nr))
    else:
        return 0

def move(fwd=0, turn=0):
    lp = int((fwd - turn) * -100)
    rp = int((fwd + turn) * -100)
    left.run(limit(lp))
    right.run(limit(rp))

def pincer(button):
    global closed
    try:
        if button and not closed:
            closed = True
            action.turn(-40, 70, emulate=False)
        elif not button and closed:
            closed = False
            action.turn(30, 70, emulate=False, brake=False)
    except motor.BlockedException:
        print action.get_tacho()

pygame.init()
j = pygame.joystick.Joystick(0) # first joystick
j.init()
print 'Initialized Joystick : %s' % j.get_name()
try:
    while True:
        pygame.event.pump()
        sleep(0.1)

        # get_axis returns a value between -1 and 1
        move(j.get_axis(axis['y']), j.get_axis(axis['x']))
        pincer(j.get_button(0))

except KeyboardInterrupt:
    j.quit()
Published on

Hidden Pages in Wordpress

More often that not, I need to hide pages from the menu and search pages, when setting up a Wordpress blog.

Usually for download and thank-you pages, or other stuff that is only accessible via a direct link.

By default, Wordpress includes a visibility settings, which has 3 values.

  • Public – anyone can see it.
  • Protected – Anyone with the password can see it.
  • Private – Only you can see it

None of them is useful for my goals, however, some digging revealed that a small change would allow you to link directly to password protected pages.

Copy wp-pass.php to unlock.php, and make the changes below.

--- wp-pass.php	2011-09-19 05:17:26.000000000 +0200
+++ unlock.php	2012-01-02 17:38:47.000000000 +0100
@@ -10,8 +10,8 @@
 require( dirname(__FILE__) . '/wp-load.php');
 
 // 10 days
-setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_POST['post_password'] ), time() + 864000, COOKIEPATH);
+setcookie('wp-postpass_' . COOKIEHASH, stripslashes( $_GET['post_password'] ), time() + 864000, COOKIEPATH);
 
-wp_safe_redirect(wp_get_referer());
+wp_safe_redirect($_GET['return']);
 exit;
 ?>

Now you can simply link to http://example.com/unlock.php?post_password=foobar&return=/thank-you/

Published on