Wiki

Clone wiki

pr2_pretouch_sensor_optical / OpticalSensorDevelopment

System Architecture

system_optical.png


PCB

The PCB schematics and layout is designed using Altium Designer. If you are at UW Sensor Systems Lab, see how to get the software here.

Design Files

The design files are in the pr2_pretouch_sensor_hardware repository on Bitbucket (direct link). Please check out the whole repository because some library files are included. Open the project file with extension PrjPcb.

Order Boards

PCB-POOL: Select 2-layer boards. Come with free stencil for using soldering paste and hot plate.


PR2 Finger Mechanical Structure

The mechanical structure for mounting the sensor is designed in Solidworks. If you are at UW Sensor Systems Lab, see how to get the software here.

Design Files

The design files are in the pr2_pretouch_sensor_hardware repository on Bitbucket (direct link). STL files are for 3D printer, and SLDPRT files are the Solidworks design files.

3D printer

The 3D printer is located in CSE 003. You need CSE account to logon to the desktop. Ask a lab member if you don't have one.


Microcontroller Firmware for the Sensor

The microcontroller used for the sensor is AVR ATmega168PA, but ATmega328(P) can be used as well. The datasheet is an important reference to understand the source code and the functionalities of the chip.

Source Code

The code can be found in the pr2_pretouch_sensor_optical repository on Bitbucket (direct link).

finger_optical.c: In the initialization, it configures the SPI Slave, ADC, and external interrupt. The main infinite loop just waits for the internal interrupt signal sent from the Master (Picoblaze on the gripper), do the ADC sampling, prepare the sampled data in the SPI register, and wait for the SPI transmission clock from the Master.

Required Tools

  • avr-lib: a library to provide a high quality C library for use with GCC on Atmel AVR microcontrollers. Install the release version under Ubuntu:

    sudo apt-get install avr-libc
    
    or download, compile, and install the latest version.

  • avrdude: download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers for using the in-system programming technique (ISP). Install the release version under Ubuntu:

    sudo apt-get install avrdude
    
    or download, compile, and install the latest version.

Compile the source code

There is a Makefile for the code, so just run:

make

Using the AVR Dragon programmer

Plug the programmer's USB cable, and connect the sensor board connector with the AVR ATMega programmer as this picture: IMG_20140604_133913.jpg =50x50.

If you are prototyping using a DIP chip, you can use the ZIF socket to program it.

You can test the whether the connection is correct by trying to communicate with the micro:

sudo avrdude -c dragon_isp -p atmega168p -B 16 -v
```sh


### Configure the microcontroller on the PCB
AVR microcontrollers require their fuses to be programmed in order to setup the correct configuration. Some basic tutorial can be found online ([link](http://www.ladyada.net/learn/avr/fuses.html)). A useful fuse value calculator can be used to determined the appropriate fuse byte values ([link](http://www.engbedded.com/fusecalc)). The datasheet has detail definition of all the fuse bytes.

In the case of this optical sensor, the only thing needs to be change is disabling "Divide clock by 8 internally [CKDIV8=0]". The ATMega168PA chip provide internal 8MHz system clock, but by default it was divided by 8, resulting 1MHz clock. We want to change it so we can use the full power (8MHz).

On a fresh chip, use this command to check the current default fuse values:
```sh
sudo avrdude -c dragon_isp -p atmega168p -v
sudo is required to give write access to the USB programmer. You should see it shows:
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as 1

To disable "Divide clock by 8 internally", we want to set the CKDIV8 bit, so the lfuse value should be changed from 62 to E2. Change the value using this command:

sudo avrdude -c dragon_isp -p atmega168p -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m
Now check the current fuse value again:
sudo avrdude -c dragon_isp -p atmega168p -v
You should now see it shows:
avrdude: safemode: lfuse reads as E2
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as 1

Program the microcontroller on the PCB

Program the micro on the PCB:

sudo make program


Sensor Hardware Assembly

Assemble the PCB and the 3D-printed mechanical structure.


Using the PR2 Development Gripper

We have a standalone development gripper at UW Sensor Systems Lab.

Connection

IMG_20140606_160139.jpg

  1. Connect the ethernet cable to the computer. You can use a USB ethernet adapter to have the connection along with the regular network.
  2. Set the power supply to 18V WITHOUT connecting it to the gripper
  3. Set “Output Off “on the power supply
  4. Connect the power cables to the gripper (+ to Red; - to Black)
  5. Set “Output On “on the power supply

Important: Do not connect the power cables while the Output is On.


Picoblaze Firmware for the Gripper

Picoblaze is a soft-processor (essentially a microcontroller) running on a Xilinx FPGA, which is on the PR2 gripper's motor control board (WG006). The program uploaded and running on the Picoblaze will be erased when power-cycled. Therefore, everytime you power-cycle the gripper (WG006) or the whole robot, you need to re-upload the program.

Source Code

The code is written in Assembly, according to the Picoblaze syntax (User Guilde).

The code can be found in the pr2_pretouch_sensor_optical repository on Bitbucket (direct link).

picoblaze_optical.s: The first half of the code is the definition of the soft processor registers. The init setup the SPI clock frequency, and the Timer A or Timer B, which defines the sampling rate of the sensor. main_loop defines the logic of this master program. It iterates based on the Timer, assert the SPI nChipSel1 (the signal is also used for External Interrupt on the microcontroller to start one ADC conversion), wait for the ADC and data transferred into the SPI buffer, and then call the read_sensor subroutine to send out 8 SPI clocks to get 1 bytes of data from the slave (microcontroller).

Required Tools

The required tools are contained in the pr2_ethercat_hardware repository, and should have been checked out when you did the software setup in the main Wiki page.

Compile

If this is the first time you use it, you may need to compile the picoasm binary:

cd ~/optical_ws/src/pr2_ethercat_drivers/wg006_fingertip_dev/picoasm
make

Go back to your catkin workspace's src folder:

cd ~/optical_ws/src

Then compile the source code:

./pr2_ethercat_drivers/wg006_fingertip_dev/picoasm/picoasm -i ./pr2_ethercat_drivers/wg006_fingertip_dev/firmware/optical_fw.s -H ./pr2_ethercat_drivers/wg006_fingertip_dev/firmware/optical_fw.hex

Upload

Upload the Picoblaze firmware for the gripper’s FPGA (Do it everytime the robot is power-cycled)

For the standalone development PR2 gripper:

pr2-grant ./pr2_ethercat_drivers/wg006_fingertip_dev/tools/picoblaze_prog -r ./pr2_ethercat_drivers/wg006_fingertip_dev/firmware/optical_fw.hex -ieth1 -p1 -W

For the actual PR2 grippers: Left gripper:

pr2-grant ./pr2_ethercat_drivers/wg006_fingertip_dev/tools/picoblaze_prog -r ./pr2_ethercat_drivers/wg006_fingertip_dev/firmware/optical_fw.hex -iecat0 -p25 -W
Right gripper:
pr2-grant ./pr2_ethercat_drivers/wg006_fingertip_dev/tools/picoblaze_prog -r ./pr2_ethercat_drivers/wg006_fingertip_dev/firmware/optical_fw.hex -iecat0 -p25 -W

Using Script to Both Compile and Upload

For the standalone development PR2 gripper:

./pr2_ethercat_drivers/wg006_fingertip_dev/upload_optical_firmware_dev_gripper.sh

For the actual PR2 grippers (both left and right):

./pr2_ethercat_drivers/wg006_fingertip_dev/upload_optical_firmware.sh

Publishing the Sensor Data

On the robot

On the robot, please refer to the main Wiki page for the "Start the Optical Sensor Publisher" section.

On the Dev Gripper

Instead of starting the robot, you need to start the real-time loop:

cd ~/optical_ws
roscore
pr2-grant ./devel/lib/pr2_ethercat/pr2_ethercat -ieth1 -x ./src/pr2_ethercat_drivers/wg006_fingertip_dev/robot.xml
Then just follow the same following instruction after that to get sensor data. For more information regarding running the realtimeoop, read on the pr2_etherCAT ROS Wiki page (note that the package name pr2_etherCAT has been changed to pr2_ethercat in Hydro).

Trouble shooting

  1. If you see similar ROS error messages like this when running some of the program: ''' [rospack] Warning: no such package ethercat_hardware ''' It's probably becuase you did not source the catkin workspace's source.bash file. Overlay this workspace on top of your environment automatically on new terminals by adding this to your .bashrc. Change the workspace name optical_ws above to what you used:
    source $HOME/optical_ws/setup.bash
    
  2. Not able to successful communication with the AVR microcontroller using the AVR Dragon programmer: Please make sure the connection the soldered wires on the AVR Dragon programmer is not detached. The connection is based on the following document: AVR Dragon guide 1 AVR Dragon guide 2 Official Connection The gripper ribbon cable pin outs

Updated