Page 1 of 1

Unexpected difficulty

PostPosted: Wed Apr 29, 2015 10:30 am
by Puma
I'm having a great time exploring the different projects I can do, even implemented face tracking, which is obviously quite complex, but do you think I can do something as simple as control the robot's motions via keyboard? currently the answer to that question is no.

All I want to do is use the UP/Down/Left/Right arrow keys to control the robots movement, eg Up arrow equals forward, Down arrow equals reverse, no key pressed equals stop

I need to be able to do this via the wifi, I looked at your script robot_control_test.py, but this requires robot_web_server to be stopped.

In summary, I need to know how to read the keyboard and send the commands via wifi, any help is appreciated.

P.S thank you for helping getting me back into my favourite hobby.

Re: Unexpected difficulty

PostPosted: Wed Apr 29, 2015 4:15 pm
by Alan
Hi there,

I think that instead of using the script robot_control_test.py (which runs on the robot) you may be better of using the py_websockets_bot library which communicates with the robot over WiFi.

This blog post here provides a tutorial explaining how to get started with the py_websockets_bot library. I think that the script closest to the one you want is motor_test.py which shows how to control the motors of the robot.

Keyboard input via the command line for Python is a bit difficult as you can ask for an input string from the user with the input command, but it's hard to continuously read the arrow keys which I suspect is probably closer to what you want. One way that you could do it would be to create a small GUI application using either PyGame or wxPython. You could use that library's keyboard handling routines and then use the py_websockets_bot library to control the robot.

Hopefully that's some help. Let me know if you need more detail on anything.

Regards

Alan

Re: Unexpected difficulty

PostPosted: Sat May 02, 2015 2:54 pm
by Puma
Thanks for the help Allan, those modules gave me access to other things I was looking for.

If I can impose on you for further help, I have a 4 pin ultrasonic sensor with trigger and echo pins, what I'd like to do is connect these to D0 and D1 on the Dagu mini driver board(I won't be using them for serial any time soon) can you advise me on how to set those pins and read/write them please?

Re: Unexpected difficulty

PostPosted: Mon May 04, 2015 4:58 pm
by Puma
Further question "bot.set_neck_angles" to position the neck, but I've noticed that when changing angle, especially the pan angle, it puts quite a load on the servo because of the speed the angle changes, I know I can slow down using smaller increments, but I'd rather if possible slow the servo motor itself, is this possible?

Re: Unexpected difficulty

PostPosted: Mon May 04, 2015 8:07 pm
by Alan
Hi there,

It's not possible to slow it down I'm afraid as the servo motor is just trying to get to the target angle as soon as possible. Sending over the angle change in smaller increments is probably your best bet, although I think that as long as your camera cable is free to move then there shouldn't be any harm in letting the servo turn quickly.

Regards

Alan

Re: Unexpected difficulty

PostPosted: Tue May 05, 2015 3:39 pm
by Puma
Thanks Allan, camera ribbon cable is no problem, I purchased a 20cm ribbon to allow more flexibility.

My concern is actually with the mechanics of the servo, nylon cogs might be tough, but the sudden stop start must be putting quite some strain and wear on them.

I do have an idea to adjust the power to the pan servo using another PWM output, basically plugging the servos +v lead to the PWM output, if my theory is right I should be able to slow the servo motor, in theory.

Re: Unexpected difficulty

PostPosted: Wed May 06, 2015 7:41 pm
by Alan
Hi there,

Apologies if I've misunderstood, but I'm not sure that trying to connect servo +V to PWM outputs will give you great results I'm afraid. Basically, the problem is that the pins on the mini driver and the Pi can't provide more than a small amount of current (about 40mA for the mini driver). The neck servo motors are small but I would think that they'll still draw a lot more current than this, especially under load.

What you could try instead is using a transistor to swtch the servos on and off as someone else was trying to do here. Although it looks like it could get a bit complicated.

I think that a software change may be your best bet, and probably the easiest place to do it is in your control script. Let me know how you get on with your experiments. I'm a bit snowed under at the moment but I can create a code sample showing a possible solution if you think it'd help.

Regards

Alan

Re: Unexpected difficulty

PostPosted: Sat May 16, 2015 3:51 pm
by kevcook
Puma,

Did you get the HC-SR 4 pin sensor working via the driver and not the GPIO? I'm looking to do the same thing but am struggling to get it working without risking the Aduino and the Pi?

Kevin.

Re: Unexpected difficulty

PostPosted: Wed May 20, 2015 11:35 am
by Alan
Hi there,

Sorry I completely missed the earlier post asking about HC-SR04 support.

I believe (although haven't tried it myself) that it's possible to use the 4 pin sensor instead of the 3 -pin sensor simply by connecting the send and receive lines together (as shown here). If you have a soldering iron then a quick solder bridge should work.

If anyone with an HC-SR04 has time to test this then if all is well I'll update the sensor blog post so that other people know it's possible.

Regards

Alan

Re: Unexpected difficulty

PostPosted: Mon May 25, 2015 6:45 pm
by kevcook
Thanks, Alan. I made a link and used that into D12 and it worked fine triggering at various values. I'm just using it to detect an obstacle so a simple read was all that was needed. 6cms away gives a data value of 35 and that triggers a sub routine to stop and avoid. It works for me.
Thanks.