OpenCR - How to use current stuff (develop branch)

Not sure if this is the best place to discuss this, but I thought I would semi-document something we discussed in an github issue (SPI Transaction support plus... · Issue #91 · ROBOTIS-GIT/OpenCR · GitHub). That is a reasonable way to work with the current Open CR sources.

What I was doing before was to copy over all of the sources from the develop branch (or my current sub-branch) over the version I installed using the standard way that is then created in the Arduino15 drectory…

This Worked OK, but then I had to remember to update that directory and if I made changes had to remember to copy those changes back to my github install…

What I am trying now, is to have two versions of the OpenCR in the the Arduino boards type menu. The main one that was installed using the default instructions: OpenCR 1.0

I then have my fork of the OpenCr (GitHub - KurtE/OpenCR: Software for ROS Embedded board (a.k.a. OpenCR). OpenCR means Open-source Control Module for ROS.) which I cloned down to d:\github\OpenCR, which if I am not making any changes I typically leave in the branch (develop) and I routinely update my fork with the contents of the official develop fork.

Not sure if anyone cares about this part, but I have a batch file to sync my develop branch: syncopencr.bat

d:
cd cd \GitHub\OpenCR
git fetch upstream
git checkout develop
git reset --hard upstream/develop
git push origin develop --force
c:

I ran this from a command window. Warning it can be dangerous, as if you try to run this with a bunch of outstanding changes it will clobber them.

Again side note: If I am making any changes, I will create a new branch that is derived from this one to do my changes in. This new branch is the branch that I then issue any Pull Requests from.

But now back to the subject of this posting. How to use this copy of the OpenCR sources in Arduino.

What I have done is to, go to my Arduino Sketch folder, and if you don’t already have a Hardware directory, create it. In my case it is: c:\Users\kurte\documents\Arduino\hardware

I then create a new directory: opencr

In this directory, I create a symbolic link in this directory:
opencr → [D:\GitHub\OpenCR\arduino\opencr_arduino\opencr]

Note: as you can probably tell I am doing this under Windows (actually windows 10 64 bit current version).
For this I use the command mklink:

That is I believe the command I did while I had a command prompt (might need administrator version) was:

mklink /D opencr D:\GitHub\OpenCR\arduino\opencr_arduino\opencr

I have not tried it, but there are similar commands in Linux and on the MAC for the same thing.

Then I restarted the Arduino IDE, and if I then go to the tools->Board menu OpenCR will show up in two places. The one is using your normal Arduino Install and the other will use the current sources. Note: It actually appears to use the default installs tools, but the files are coming from the current stuff.

To make it more obvious to me which one is which, I edited the boards.txt file in my copy of the OpenCR develop branch and changed the name:

OpenCR.name=OpenCR Board(develop)

So now the current sources version shows up with the updated name.

Again not sure if anyone else is interested in this, but thought I would document what I have done.

Kurt

2 Likes

Thanks for your sharing :slight_smile:

I think it would be nice to change this post to WiKi mode so that others can add/edit it. (like this)

For more details about “Wiki Post”, please refer to “What is a Wiki Post?”

Thanks,

Not sure quite how to do it? The first link, looks more like how to convert a whole forum from openPHP to discourse.

The second link looks promising, but I don’t have the wrench symbol. Which I think implies I don’t have enough privileges to do so?

Oh, I’m sorry. I do not have privileges, too…
In this forum, only admin account is set to be able to set wiki post.

If there is a better way or a new opinion, it would be better to leave the answer in this post :slight_smile:

Again not sure if this is the best place to talk about being able to remotely update the OpenCR board, but I am making progress :smiley:

Note: I am running this on Windows 10 and I am using the utilities that come with the PuTTy program, I know that we can do similar for other platforms…

Yesterday, I was able to get my Robotis OpenCR board type, to be able to upload the compiled binary to my UP board :smiley:

The OpenCR’s boards.txt already had a menu item: Upload method:

menu.upload_method=Upload method

Which had one item in it, defined like:

OpenCR.menu.upload_method.UploadMethod=OpenCR Bootloader
OpenCR.menu.upload_method.UploadMethod.upload.protocol=opencr_ld
OpenCR.menu.upload_method.UploadMethod.upload.tool=opencr_ld

So I added another menu item by adding new section like:

OpenCR.menu.upload_method.pscp=PSCP UP Turtle
OpenCR.menu.upload_method.pscp.upload.protocol=pscp
OpenCR.menu.upload_method.pscp.upload.tool=pscp

When I restart Arduino IDE it shows this new menu item.

Then I added definition for this command in platform.txt… Currently it looks like:

tools.pscp.cmd=pscp
tools.pscp.cmd.windows=pscp.exe
tools.pscp.path=C:/Program Files/PuTTY

tools.pscp.upload.params.verbose=-d
tools.pscp.upload.params.quiet=n
tools.pscp.upload.pattern="{path}/{cmd}" "-batch" "-pw" "MY Password" "{build.path}/{build.project_name}.bin" "kurt@192.168.2.12:/home/kurt/opencr_update"

Note: I edited the password here… Also I should tun on the -batch flag to make sure it does not try to prompt…

With this I was able to select my new Upload method and when I do an upload command, it actually used pscp (of Putty install) and sent the file over to my up board :smiley:

First Question: Is there an easy way to not have to hard code, the other computers IP address, user name, password… Would be nice if Arduino IDE had way to add menu item that allowed you to enter string to save away…

My quick look at ESP… integration, to update using a Java app, that maybe allows them to select some stuff? Wonder if need to do same… Or maybe start off, can I use environment variables… Or maybe to start off with, maybe can edit Arduino’s preferences.txt file and add keys for this…

Next up is how to use it on the UP board… Again. First pass I have a shell script that I am running in my
opencr_update directory. Currently is not fully rounded out and again hard coded for specific program.
But it looks like:

#!/bin/sh

architecture=""
case $(uname -m) in
    i386)   architecture="386" ;;
    i686)   architecture="386" ;;
    x86_64) architecture="amd64" ;;
    armv7l) architecture="arm" ;;
    arm)    dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac

echo $(uname -m)
echo $architecture

shell_cmd=""
if [ "$architecture" == "arm" ]
then
  shell_cmd="./opencr_ld_shell_arm"
else
  shell_cmd="./opencr_ld_shell_x86"
fi

while :
do
	inotifywait up_turtlebot_waffle.ino.bin
	$shell_cmd make up_turtlebot_waffle.ino.bin waffle_custom 1.0.0 
	$shell_cmd /dev/ttyACM0 115200 waffle_custom.opencr 1
done

Note: the above script uses the inotifywait command that I needed to install

apt-get install inotify-tools

I then use a putty window and start up this shell script and as soon as the arduino ide puts the binary over on my UP it tries to run the commands to convert the output to the right format and then update the opencr board.

Next Question: Is there a better way to run the update… Maybe a few options:
a) Cleanup the shell script… Maybe try to add it automatically at boot?.
b) Wonder if I could add one or more additional command patterns to the upload option, that maybe uses something like plink to generate a command to run on the host… Potentially if the answer to earlier question is to use some external app, like one in Java, than probably it could handle that as well?

Anyway making progress! Suggestions very much hoped for :wink:

1 Like

Some updates for the previous post. Will probably soon fold into previous post:

As I mentioned, I don’t want to hard code things like my password into this, likewise things like user name and IP address. So I am trying another approach which looks like it is working.

With pscp (again part of PuTTy) you can instead of use a Putty Saved Session name instead of the host name. The saved session has the IP address as part of it, in addition it can have the user login name. PuTTy (unlike KiTTy) does not have the ability to include the password as of the saved session. However they both have the ability to remotely log in using Public key and they have the ability to point to the private key file.

There are several websites that give instructions on how to use puttygen to create the public keys, including: How To Create SSH Keys With PuTTY to Connect to a VPS | DigitalOcean and Connect to your Linux instance from Windows using PuTTY - Amazon Elastic Compute Cloud

So I setup to use a fixed Session Name: OpenCr_Host, which can be configured for whatever IP address, user name.

######
tools.pscp.cmd=pscp
tools.pscp.cmd.windows=pscp.exe
tools.pscp.path=C:/Program Files/PuTTY

tools.pscp.upload.params.verbose=-d
tools.pscp.upload.params.quiet=n
tools.pscp.upload.pattern="{path}/{cmd}" "-batch"  "{build.path}/{build.project_name}.bin" "OpenCr_Host:./opencr_update/opencr_upload.bin"

I also hard coded a name to upload the binary file to, such that the script on the other side should be able to program the board with whatever Arduino program I decide to upload.

I also renamed the upload method from “PSCP UP Turtle” to “Remote Upload”

OpenCR.menu.upload_method.pscp=Remote Upload
OpenCR.menu.upload_method.pscp.upload.protocol=pscp
OpenCR.menu.upload_method.pscp.upload.tool=pscp

The batch script was also updated some, to hopefully work on x86 or ARM hosts.

#! /bin/bash


architecture=""
case $(uname -m) in
    i386)   architecture="386" ;;
    i686)   architecture="386" ;;
    x86_64) architecture="amd64" ;;
    armv7l) architecture="arm" ;;
    arm)    dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac

echo $(uname -m)
echo $architecture

shell_cmd=""
if [ "$architecture" == "arm" ]
then
  shell_cmd="./opencr_ld_shell_arm"
else
  shell_cmd="./opencr_ld_shell_x86"
fi

echo "OpenCR Update Start.."
if (($#==2))
then
  $shell_cmd $1 115200 $2 1
else
  echo "wrong parameter "
  echo "update.sh <port> fw_name"
fi

exit

Some of the earlier questions have not been answered yet, like maybe attempt to automatically start the update script at boot, or maybe moving it’s work back over to Arduino using some remote commands…

Also if I had more OpenCR boards, hosted on multiple hosts, I might be tempted to add another menu in tools menu, with maybe a set of 5 hard coded session names, that you can than setup or not and choose which one to use…

Also I may move the update script to be at the users home directory and not the opencr_update directory as the current instructions say to update your opencr code with the current stuff, the first step is to delete the opencr_update directory…

Then there is the issue of how to do this with Linux and MAC… But at least it is showing progress :smiley:

In case anyone want’s to look at the actual changes, I pushed a copy of these files/changes to a new branch of my fork of OpenCR project: https://github.com/KurtE/OpenCR/tree/remote-upload

Another quick update:

I decided to try out some of these changes on my Linux Box (64 bit PC Ubuntu 16.04).

There are some obvious issues like pscp is the windows version of the linux command scp.

So I edited the platform.txt to make a different command line and app used for windows versus linux.

I needed differences as the options were different.

I wanted to also not have to hard code in passwords here so used, so wanted to setup keys to use…
I followed instructions in: How To Set Up SSH Keys on Ubuntu 12.04 | DigitalOcean

I also did not want to hard code in my IP address or user name…

So created the file : ~/.ssh/config
file to create an alias to the user and IP address, using the
same logical hostname OpenCR_Host (Same name as the Putty configuration)
The file looked something like:

Host OpenCR_Host 
    User kurt
    HostName 192.168.2.12

That allows me to just ssh or scp to OpenCR_Host and so far it appears to work… Updated new branch

Cool!

I think it would be nice to update as an option.
For users who use SBC, it would be convenient to upload the binaries built on PC directly to OpenCR via SBC.
Of course, although it contains an absolute path and depends on a specific platform, I think it is very good as an option.

Thanks, I do believe I can remove some of the hard links…

Right now trying to figure out why when I download a program through current stuff, that at times the USB serial port is not properly being setup…

The code is setup to download it to my up board, as you can see: in the output

Using library DynamixelWorkbench at version 0.1.0 in folder: C:\Users\kurte\Documents\Arduino\hardware\opencr\opencr\libraries\DynamixelWorkbench 
Sketch uses 177344 bytes (22%) of program storage space. Maximum is 786432 bytes.
Global variables use 61024 bytes of dynamic memory.
C:/Program Files/PuTTY/pscp.exe -batch C:\Users\kurte\AppData\Local\Temp\arduino_build_980276/up_turtlebot_waffle_ir_cliff.ino.bin OpenCR_Host:./opencr_update/opencr_upload.bin 

up_turtlebot_waffle_ir_cl | 4 kB |   4.0 kB/s | ETA: 00:00:42 |   2%
up_turtlebot_waffle_ir_cl | 174 kB | 174.7 kB/s | ETA: 00:00:00 | 100%

I have the script running on the remote machine…

kurt@kurt-UP-Turtle:~/opencr_update$ cat remote_update.sh
#!/bin/sh

architecture=""
case $(uname -m) in
    i386)   architecture="386" ;;
    i686)   architecture="386" ;;
    x86_64) architecture="amd64" ;;
    armv7l) architecture="arm" ;;
    arm)    dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac

echo $(uname -m)
echo $architecture

shell_cmd=""
if [ "$architecture" == "arm" ]
then
  shell_cmd="./opencr_ld_shell_arm"
else
  shell_cmd="./opencr_ld_shell_x86"
fi

while :
do
        inotifywait opencr_upload.bin
        $shell_cmd make opencr_upload.bin opencr_upload 1.0.0
        $shell_cmd /dev/ttyACM0 115200 opencr_upload.opencr 1
done

Output from script:

Setting up watches.
Watches established.
opencr_upload.bin MODIFY
opencr_ld_shell ver 1.0.0
make firmware...
[  ] file name          : opencr_upload.bin
[  ] file size          : 0 bytes
[  ] fw_name            : opencr_upload
[  ] fw_ver             : 1.0.0
[OK] finished           : 1288 bytes
opencr_ld_shell ver 1.0.0
opencr_ld_main
[  ] file name          : opencr_upload.opencr
[  ] file size          : 1 KB
[  ] fw_name            : opencr_upload
[  ] fw_ver             : 1.0.0
[OK] Open port          : /dev/ttyACM0
[  ]
[  ] Board Name         : OpenCR R1.0
[  ] Board Ver          : 0x17020800
[  ] Board Rev          : 0x00000000
[OK] flash_erase        : 0.00s
[OK] flash_write        : 0.00s
[OK] CRC Check          : 0 0 , 0.001000 sec
[OK] Download
[OK] jump_to_fw
Setting up watches.
Watches established.

But after it reboots the device /dev/ttyACM0 does not exist…
Looking at the dmesg output:

[  890.622002] usb 1-7.1: new full-speed USB device number 8 using xhci_hcd
[  890.730066] usb 1-7.1: New USB device found, idVendor=0483, idProduct=5740
[  890.730096] usb 1-7.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  890.730115] usb 1-7.1: Product: OpenCR Virtual ComPort in FS Mode
[  890.730130] usb 1-7.1: Manufacturer: ROBOTIS
[  890.730144] usb 1-7.1: SerialNumber: FFFFFFFEFFFF
[  890.732460] cdc_acm 1-7.1:1.0: ttyACM0: USB ACM device
[  920.063943] cdc_acm 1-7.1:1.0: failed to set dtr/rts
[  920.120162] usb 1-7.1: USB disconnect, device number 8
kurt@kurt-UP-Turtle:~/catkin_ws/src$

Not sure yet if this is due to running through the remote multiple step… Or because of the latest stuff that I have using develop branch, plus a few minor changes.

Look into Zeroconf
also look at the /etc/default a value of 1 may need to be set to zero depending on if your ip address
is static or dynamic. If you get it working you can use names vice address.