Kurt's Raspberry Pi (and BeagleBone Black)

I picked up that wifi dongle you posted about. Is it still working for you? I was getting tired of the legs tripping on the network cable. :slight_smile: Also last night I came up with a simpler way to calculate the servo speed instead of using that function from robosavy you played around with back in your development with the phantomX. I simply found a factor that I multiply the angle difference of the curPos and goalPos by for all three joints.


int ServoDriver::CalculateAX18MoveSpeed(int wCurPos, int wGoalPos, int wTime)
{
  int wTravel;  // Angle amount of travel
  int factor;   // Factor to calculate speed 
  int wSpeed;   // Speed value to return for packet creation
  
  // find the amount of travel for each servo
  wTravel = abs ( wGoalPos - wCurPos );

  factor =  pow ( wTravel, 2 ) * 2.93;

  wSpeed =  factor / wTime;

  if (wSpeed > 1024) wSpeed = 1024;

  return wSpeed;
} 

Itā€™s not perfect on the very highend or very low end but it works rather well in the middle. Iā€™m trying to track down a ā€œglitchā€ at the moment. Every once in a while I see a leg jerk in itā€™s movement. Usually when I reverse movementā€¦ For example from a full forward to a full reverse. Itā€™s very odd. Iā€™ll have to throw in some printf statements to see if itā€™s actually in the angles or if it is a packet glitch.

Sounds good.

Yes, I am still using the dongle on mine. Note: It is powered by the powered USB hub. So far it works well. It did change my IP address that I needed to PuTTY to. When I first was using the Pi I was connecting to 192.168.2.106, now it is to 192.168.2.100. Found that by connecting in the HDMI cable and seeing what IP address was createdā€¦

The little sound box arrived today. So I plugged it in and it appears to work. At least I can use festival or espeak to make it say something. Now to integrate it into the code. Also want to check to see how hard it is to have it play notesā€¦

On a side note, I ordered a second Pi, plus Card, plus this time I am trying a different dongle with an +5db antenna. Over time would like to setup a rover with this and maybe a USB camera and see how far I can drive one of my rovers remotelyā€¦

Kurt

So in order to save space on the hex I decided to remove the case on my USB hub. As a precaution I shrink wrapped it to keep the wires secure. As you can see the size with the plastic off is quite smaller. I can actually mount it under the raspberry pi since its standoffs are so high.

So I was looking at the hub last night. If I wanted to make it powered. Would it be as simple as cutting the 5V incoming from the Rpi and hooking it up to my BEC?

The answer is maybe? At least I saw one diy project yesterday where someone added a power jack to a USB hub by soldering to the +5/GND pins of one of the usb connectorsā€¦

Note: my current hub I can then run a cable from one of the USB ports back to the power USB port on the PI and it works. With my other hub it does not as it tries to conserve power and turns off the hub if no power is coming in from the input USB connectorā€¦ Will see what the new one does when it arrives for the new Pi

Kurt

Question: Now that I have Espeak and Festival installed, what is the best way to install the header files/libraries to use them within my program to allow me to have the program say something.

Also is there any simple library out there that allows me to generate simple notes to play on the speaker? I think there is some form of Beep command, but it only goes to the onboard buzzer (which I donā€™t think there isā€¦).

Thanks
Kurt

I havenā€™t integrated Espeak and Festival yet. I was just using simple system command calls to pipe out to it. Not really a complete solution.

As far as a simple beep you could always look at the gpio pins and do it in a similar fashion like you do it on the arduino.

Thanks, right now trying to avoid having to add simple speakerā€¦

Currently working on trying to build a simple function into the Pi program to say somethingā€¦ So Searching around I found some postings like:
cstr.ed.ac.uk/projects/festi ā€¦ tml#SEC132

Looking over another place, I have a simple function

[code]#include <stdio.h>
#include <festival/festival.h>

void SaySomething (char *psz) {
EST_Wave wave;
int heap_size = 210000; // default scheme heap size
int load_init_files = 1; // we want the festival init files loaded

festival_initialize(load_init_files,heap_size);

// Say simple file
//festival_say_file("/etc/motd");

festival_eval_command("(voice_ked_diphone)");
// Say some text;
festival_say_text("hello world");

// Convert to a waveform
festival_text_to_wave(psz,wave);
wave.save("/tmp/wave.wav","riff");

// festival_say_file puts the system in async mode so we better
// wait for the spooler to reach the last waveform before exiting
// This isn't necessary if only festival_say_text is being used (and
// your own wave playing stuff)
festival_wait_for_spooler();

}

[/code]
Again liftedā€¦ I installed the festival dev stuff to get header files and libraries. I think the command was:
sudo apt-get install festival-dev

I may have installed some other ones as well.

I also updated my makefile to include some additional libraries.
-L/usr/lib/libFestival.a
-L/usr/lib/speech_tools/lib/libestools.a
-L/usr/lib/speech_tools/lib/libestbase.a
-L/usr/lib/speech_tools/lib/libeststring.a

But I am still getting lots of link errors.

speak.o: In function `SaySomething(char*)': /home/pi/Desktop/RPI-Test/speak.cpp:5: undefined reference to `EST_Wave::EST_Wave()' /home/pi/Desktop/RPI-Test/speak.cpp:9: undefined reference to `festival_initialize(int, int)' /home/pi/Desktop/RPI-Test/speak.cpp:14: undefined reference to `EST_String::EST_String(char const*)' /home/pi/Desktop/RPI-Test/speak.cpp:14: undefined reference to `festival_eval_command(EST_String const&)' speak.o: In function `EST_Chunk::operator--()': /usr/include/estools/EST_Chunk.h:129: undefined reference to `EST_Chunk::~EST_Chunk()' ...
Trying to figure out what else I need to include or other changes needed in make file

Kurt

My Second Pi arrived today, so I thought I would try to gather some of the information on stuff on how I go about setting up the Pi so I donā€™t lose the information, in case I need to setup a 3rd one.

First link to Quick start: raspberrypi.org/quick-start-guide

Next Initial information from Kevin that I used to do some initial setup.

Also if setting up a PC to talk to a PI through the network, more information from Kevin:

Note: On the first boot, I also use the configuration program, to resize the main partition to the size of the SD card, plus time zone, keyboard typeā€¦ If I missed changing anything can always bring this utility back up by typing: sudo raspi-config

To Add a different user other than pi, you can do something like: sudo adduser kurt
It will prompt you for some stuffā€¦
Then to make a super user:

On this 2nd Pi I am trying a different USB Wifi adapter that has an external 5dbi gain antenna ( amazon.com/GMYLE-Wireless-80 ā€¦ pd_cp_pc_0 ) that probably will have a longer range. On the first Pi I did a bunch of manual stuff to get it up and working with my network. This time I simply had the GUI up (startX) and ran the Wifi Config program on the desktop and was able to see my network, choose the right AP, entered in the WPA key and so far it appears to work :smiley:

Will probably add more later. At some point would be good to have a cheat sheet (possibly itā€™s own thread) with enough information to install enough stuff to be able to take a new Pi and do all of the steps necessary to be able to load up something like my (or Kevinā€™s) Raspberry Pi version of the Phoenix code or other robot.

Side note: made progress in being able to do speech output from my Phoenix Code :smiley:. Also created a new github project with my Raspberry Pi stuff.

Edit: I have been playing around with installing everything necessary to be able to install my Phoenix code on this Pi and be able to compile it.
I installed it by using the following commands:

First currently code is dependent on using espeak code. Will probably make this optional laterā€¦ To install the necessary stuff you need to do something like:

sudo apt-get install espeak
sudo apt-get install libespeak-dev

Note: you should then try to configure espeak and see if you can get it to work. More information earlier in this thread, but look at the data up at the link: elinux.org/RPi_Text_to_Speech_%2 ā€¦ nthesis%29

Then you can copy or git the sources that I have up on github. The commands I did to do this is:

cd ~
mkdir git
cd git
 git clone git://github.com/KurtE/Raspberry_Pi 
cd Raspberry_Pi/Phoenix 
make

Also My code is setup to use an XBee and an SSC-32, both of which connect up as USB devices. I did not want my
code to have to depend on the order the devices are added so I wished to setup rules to create an alias for these devices
I found a lot of good information up at: hintshop.ludvig.co.nz/show/persi ā€¦ l-devices/
Note: I had to experiment as some of the devices would hang, so I had to find the right command sequence to work.
Example: udevadm info --query=property --name=ttyUSB0

From this I created a file named 99-usb-serial.rules in the /etc/udev/rules.d directory. A copy of mine from the first
Raspberry Pi is contained in the Phoenix directory. It looks like:
SUBSYSTEM==ā€œttyā€, ATTRS{idVendor}==ā€œ0403ā€, ATTRS{idProduct}==ā€œ6001ā€, ATTRS{serial}==ā€œA800fcloā€, SYMLINK+=ā€œttyXBEEā€
SUBSYSTEM==ā€œttyā€, ATTRS{idVendor}==ā€œ0403ā€, ATTRS{idProduct}==ā€œ6001ā€, ATTRS{serial}==ā€œA4014UWEā€, SYMLINK+=ā€œttySSC-32ā€

Note: You will have to change the {Serial} value (and maybe some others if not FTDI) to the actual device on your machine.

Aflter I installed this file, if I type something like:
ls -l /dev/ttyXBEE

I see something like:
lrwxrwxrwx 1 root root 7 Dec 31 1969 /dev/ttyXBEE -> ttyUSB0

More later

Kurt

So here is a quick video of the robot. Everything is in and functioning! Iā€™m always obsessed with smooth movements so usually any video I do is using a gait speed set really slow. One thing to note is Iā€™m letting the Dynamixelā€™s interpolate the step. I send one sync_write per goal position to keep the traffic through the USB2AX low. Itā€™s working well with the Raspberry Pi. Next up is more refinement.

Looking good. I am glad you found a way to let the servos do some of the work!

Kurt

Been doing some more playing around with the Pi, trying to do some sound generation. Would like to add in some of the beeps I have in other versions of the codeā€¦ Been searching and hacking and have a little test program that is starting to workā€¦ Needs work to make safe, also figure out things like when is it doneā€¦ but at least I can make noise other than trying to talkā€¦

/*
* This extra small demo sends a random samples to your speakers.
*/
#include <alsa/asoundlib.h>
#include <math.h>
static char *device = "default"; /* playback device */
snd_output_t *output = NULL;
unsigned char buffer[24*1024]; /* some random data */
#define sampleRate 48000L
extern int FillSoundBuffer(unsigned char *psz, int cb, unsigned int freq, unsigned long duration);

int main(void)
{
	int err;
	unsigned int i;
	int cb;
	snd_pcm_t *handle;
	snd_pcm_sframes_t frames;
	int freq = 500;
	for (i = 0; i < sizeof(buffer); i++)
		buffer* = random() & 0xff;

	if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
		printf("Playback open error: %s\n", snd_strerror(err));
		exit(EXIT_FAILURE);
	}
	if ((err = snd_pcm_set_params(handle,
			SND_PCM_FORMAT_U8,
			SND_PCM_ACCESS_RW_INTERLEAVED,
			1,
			48000,
			1,
			500000)) < 0) { /* 0.5sec */
		printf("Playback open error: %s\n", snd_strerror(err));
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < 16; i++) {
		cb = FillSoundBuffer(buffer, sizeof(buffer), freq, 500);
		frames = snd_pcm_writei(handle, buffer, cb);
		printf ("freq %i frames: %li\n", freq, frames);
		if (frames < 0)
			frames = snd_pcm_recover(handle, frames, 0);
		if (frames < 0) {
			printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
			break;
		}
		if (frames > 0 && frames < (long)sizeof(buffer))
			printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
		freq += 250;
	}
	snd_pcm_close(handle);
	return 0;
}
int FillSoundBuffer(unsigned char *psz, int cb, unsigned int freq, unsigned long duration) {
	double sample;
	unsigned char	val;
	int	numSamples = ((long)((long)duration * sampleRate))/1000L;	// 
	printf("D: %lu RT: %lu, Samples %u\n", duration, sampleRate, numSamples);

	for (int i = 0; i < numSamples; ++i) {
		sample = sin(2 * M_PI * i / (sampleRate/freq));
		val = (unsigned char)(sample * 255);
		*psz++ = val;
	}
	return numSamples;
}

The way more complicated than it needs to be makefile looks like:

[code]#~~~~~~~~~~~~~~~~~~~~ Output File Name ~~~~~~~~~~~~~~~~~~~~
MAIN_OUT = testPCM

#~~~~~~~~~~~~~~~~~~~~ Source Files ~~~~~~~~~~~~~~~~~~~~
SOURCES =
testPCM.cpp
MAIN_OBJS:= $(subst .cpp,.o,$(SOURCES))

MAIN_DEPS:= $(subst .cpp,.d,$(SOURCES))

#~~~~~~~~~~~~~~~~~~~~ Include Directories ~~~~~~~~~~~~~~~~~~~~
INCLUDE_DIRS = -I. -I/usr/include/espeak

#~~~~~~~~~~~~~~~~~~~~ Library Directories ~~~~~~~~~~~~~~~~~~~~
LIBRARY_DIRS = -L/usr/lib/arm-linux-gnueabihf

#~~~~~~~~~~~~~~~~~~~~ Compiler Options ~~~~~~~~~~~~~~~~~~~~
COMPILE_OPTS = -Wall -pedantic -g -O2 -fno-rtti
#COMPILE_OPTS = -Wall -pedantic -g -O2

#~~~~~~~~~~~~~~~~~~~~ Linker Options ~~~~~~~~~~~~~~~~~~~~
LDFLAGS = $(LIBRARY_DIRS) -lpthread -lespeak

#~~~~~~~~~~~~~~~~~~~~ Toolchain Prefix ~~~~~~~~~~~~~~~~~~~~
TCHAIN_PREFIX=arm-linux-gnueabihf-
#TCHAIN_PREFIX=x86_64-linux-gnu-

CXX = $(TCHAIN_PREFIX)g++
CXXFLAGS = $(COMPILE_OPTS) $(INCLUDE_DIRS)

#~~~~~~~~~~~~~~~~~~~~ all ~~~~~~~~~~~~~~~~~~~~
all: begin gccversion build end

#~~~~~~~~~~~~~~~~~~~~ build ~~~~~~~~~~~~~~~~~~~~
build: $(MAIN_OUT)

$(MAIN_OUT): $(MAIN_OBJS)
$(CXX) $(CXXFLAGS) $(MAIN_OBJS) -o $(MAIN_OUT) $(LDFLAGS)

MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------

#~~~~~~~~~~~~~~~~~~~~ Eye candy ~~~~~~~~~~~~~~~~~~~~
begin:
@echo
@echo $(MSG_BEGIN)

end:
@echo $(MSG_END)
@echo

gccversion:
@$(CC) --version

#~~~~~~~~~~~~~~~~~~~~ clean ~~~~~~~~~~~~~~~~~~~~
clean: begin clean_list end

clean_list:
-rm $(MAIN_OBJS)
-rm $(MAIN_OUT)
-rm $(MAIN_DEPS)

#~~~~~~~~~~~~~~~~~~~~ backup ~~~~~~~~~~~~~~~~~~~~
backup: clean
tar cJvf ā€¦/$(MAIN_OUT)_date +"%Y-%m-%d_%H%M".tar.xz *

#~~~~~~~~~~~~~~~~~~~~ Dependency Generation
include $(subst .cpp,.d,$(SOURCES))

%.d: %.cpp
$(CC) -M $(CPPFLAGS) $< > $@.$$$$;
sed ā€˜s,($).o :],\1.o $@ : ,gā€™ < $@.$$$$ > $@;
rm -f $@.$$$$
[/code]

In order to get this to build I needed the appropriate header files and libs, which I believe I got by doing the command:

sudo apt-get install libasound2-dev

Maybe tomorrow I will try to integrate this s a function into the Phoenix code. Also need to see if it should be done on separate threadā€¦*

Hi Kevin (and others),

Progress has been a bit slow (weather is too nice ), but have been playing around some more with having the Pi be able to make some more noise

So I implemented my own code to be able to make Beep like sounds using PCM libraries. The code makes a sine wave that plays a specified amount of time with the specified frequency. Some of the memory usage can probably be cleaned up as I make the sine wave for the complete duration of the sound, where I could probably make it for one cycle and then call of to the write function N timesā€¦

Also I have the code that uses the libraries associated with espeak to be able to say strings. I also updated my code such that if I am using both of them, one will shutoff the other before trying to initialize itselfā€¦

So now my Raspberry T-Hex now does things like play three notes when the Commander is turned on and the like, and also says the name of the walking Gait when choose a new oneā€¦ Sort-of fun.

Also I fixed a variable type bug found by Kevinā€¦ (In this version, still need to fix in the Arduino code base).

If anyone is interested, the sources are up on github\kurte\Raspberry_Pi
The top level contains a readme file that hopefully has most of the steps to setup the Pi.
There are a few directories but the main one is the Phoenix directory.

Note: next up is to actually configure this Pi to startup the Hex code as system startup.

Kurt

Thatā€™s great Kurt! How is that speaker working out? I still need to buy a amplified one. Also for auto startup try adding your executable to /etc/rc.local .

Actually have 2 different ones. The one on thex is radioshack.com/product/index ā€¦ e=Speakers. I like this one better as I have more control of volume.

Thanks, will update soon to auto start hex.

Kurt

Side note:

Right now I am trying to decide if I should replace the SSC-32u on my T-Hex with something else. That is the firmware in the Beta SSC-32u is from last August and is not complete. For example it does not support binary mode, or Digital or Analog Readsā€¦ So far I have not heard anything about any updates.

Would like the ability to use a voltage divider from VS to one of the inputs and be able to know the voltage of my LifePo4 battery before it gets too lowā€¦

I have my 2nd Pi hooked up to a standard SSC-32 through a USB to TTL adapter that I also jumper the +5V over to one of the + pins to power the SSC-32. Another option would be to use an ARC32 to drive the servos (if I can find one sitting around hereā€¦)

Kurt

So if we used a Logic level converter do you think its possible to control the dynamixels directly from the pi serial port? We have both 3.3v and 5v pins available. Unless Iā€™m missing something with the right settings and parity and in my case linking the Tx/Rx lines together it could work.

Dynamixels take a different hardware driver and software.

Alan KM6VV

Yep Dynamixels are a half duplex serial interface, that you can use some hardware (as simple as a diodeā€¦) Or you can simply tie RX to TX and be very careful with your softwareā€¦

Some thoughts here. 3.3v vs 5.0v To hook up an SSC-32 to this (instead of the USB connection I have on my 2nd machine, I purchased a few logic level converters from sparkfun (sparkfun.com/products/8745) that I was going to use to hook up the SSC-32.

What I am unsure with Dynamixels if this part would be necessary or not. That is the TX will output 3.3Vs to the dynamixels. My assumption is that the Dynamixels when they transmit probably do not set a high value but only will pull signal low (Open collector or is that drain???). So they may be fine. Question then is can I set the IO level of the transmit to use a PU for the 3.3v or do you need an external PU?

Alternative would be use some external hardware to take care of the half duplex. Like I have one of these: robotshop.com/productinfo.as ā€¦ lang=en-US I would probably still need to use a voltage converter like I mentioned above.

Without the external hardware, would need to do some of the same AX12 like tricks like Arbotix people did for Arduino. Not sure how hard that would be on Pi

Note: I believe this port is pre-configured as a terminal for the PI, so we would need to disable that before another application could use this port.

Kurt

Thatā€™s clear Kurt. It was just a thought. Iā€™m totally fine with the USB2AX Iā€™ve been using. Itā€™s small and sits in the second USB port on the Rpi. I pay a slight cost on latency going through the USB so I was just thinking of ideas to reduce that. (Though Iā€™m looking into a sync_read function so latency might not be an issue. )

I already turned off the serial port terminal a while back when I was starting to play with that daughter board we purchased a while ago. Which reminds me did you ever play around with that? I have a gyroscope/accelerometer I was going to hook up to it and still havenā€™t found time to get back to it.

Alan that post probably could have been a PM to Kurt. Iā€™ve always been using Dynamixels and since Kurt and I started this endeavor together I figured it was ok to pollute his thread with Dynamixel talk. Sorry about that. :stuck_out_tongue: