Hi all !

Is someone know how to comunicate with a standalone arduino ( with RX/TX not usb ) from MRL

I try to play with serial service but don't know how to use it from main mrl mega pins.

Maybe I must use "classical" arduino command after virtual arduino declaration:

Serial.write(inByte);

but how to specify the TX port
 

Thanks

calamity

8 years 1 month ago

Hi Moz4r

MRL always send data thru the USB port on the Serial of the arduino. If you want the message to be send on another serial port of the arduino, it need to be routedat the right place inside arduino.

some times ago I have write some code to make it possible to link multiple arduino to MRL using only 1 USB connection and the multiple serial port of a Mega

http://myrobotlab.org/content/using-multiple-arduino-using-only-1-usb-c…

It is design to have MRLComm running on all the arduinos. But with the change in the MRLComm structure, it's easy to run custom code along with it if it's what you want to do.

Let me know what you want to do, I'm sure it will be easy to make it possible with MRLComm

Hi Calamity ! Great news you rocks . 

The idea is just to send "serial.write(42)" to an arduino that didn't have mrlcomm through serialX

And read the data with Serial.parseInt() ( from the standalone arduino )

 

( thank you for this sample you learn me something very intersting : connecting multiple mrlcomm with one usb )

I don't know what you are doing with your standalone arduino, maybe MRLComm can already do it and you don't know?

If MRL/MRLComm can do what you want, maybe we can integrate it into?

Another alternative is to use MRLComm as a library in your arduino script to be use as the communication device. That way  you can connect your standalone arduino like in my sample script and you can send your command with something like arduino1.CustomMsg(42) and retrive the value in the arduino main loop with a mrlcomm.readCustomMsg(). 

Maybe if you explain in more details what you are trying to do I can help better

 

Hi !  !! I will try to explain :

This is question from friends

It's for 2 things :

1/ Make a diy servo

An autonomous pid is running on nano arduino and we need to send command like this ( 20° / 120° ... )

2/ Inmoov Nano

We use another dedicated arduino to control the mouth in realtime. ( from the jack output ) . And sometime need to control the jaw from mrl ( to stop when we play music exemple )
This arduino is On when the system is shutdown and control the electrical inition off the robot ( later with maybe a rfid or onboard vocal command )

 

Data will be send as bytes like this : 0x04 0x01 0x02 0x03 0x04

 

Have a nice day

 

ok, I see

I know Mats is working to implement a diy servo service in MRL, I don't know where it is on that

Both your things can gain several advantages by using MRLComm. The main one is to be able to get a two way communication with MRL so it can gives feedback to any services in MRL.

For now, if you want to add MRLComm to your custom code, I can make the data you are sending available in the main loop and feedback answer available for the MRL python script

Hi

I started to build a DiyServo service in MRL, but it's all implemented in Java, and  uses the Motor service and an analog input from the Arduino. I still have some more testing to do before I release it. 

If someone wan't to create a DyiServo that executes on the Arduino, then the first thing to do would probably be to incude the PID library in MRLComm. 

http://playground.arduino.cc/Code/PIDLibrary

It's explained in this series, that also is the base for the PID implementation in MRL.

http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-int…

/Mats

 

ambroise

8 years 1 month ago

In reply to by Mats

hello mat

that is a very good news if you work about a diy servo

for the leg i think we use a drill motor so we need this service

thank you

amby

Calamity we send you soon a sample little script so you can understand what kind of data will be send to the arduino with custom code inside

Mats like I said it's a great great great thing . We have some interogations about this service and how mrl PID is executed. Does't MRL PID is a windows thread or an autonomous mrlcomm/arduino task ? .I said that because if we execute 10 or 20 PID is there is a risk to slow down the execution ? ( we can use multiple arduino serial connected of course ) . The real question is who is working : arduino or windows. 

Amby t es heureux la :)

 

juerg

8 years 1 month ago

I have a similar project with my self levelling hand and the control of the wrist servo.

If self levelling is activated the control of the wrist servo needs to be in the local Nano which gets the status from the orientation sensor and tries to level the hand (in sync with the added wrist bend servo).

If self levelling is deactivated the Nano should get position requests for the wrist from MRL and position it according to the MRL request.

So far I have understood that

a) I will need to combine the customMsgMrlcomm.ino code with my self levelling control loop.

b) I will need to define msg's to start/stop the self levelling and to position the wrist

c) in MRL on the Mega I would need something that will send the defined custom position request message to the Nano instead of manipulating pin 7 itself (or in addition as pin 7 will not be wired).

d) The start/stop msg's can be sent by the python script that runs for activating/deactivating the self levelling

If above makes sense my problem would be step c) - how to modify the wrist position commands to be a send msg?

 

The best way will alway to use what MRL/MRLComm can offer to you. It will help you by having your sensor data or device been used with any other service in MRL. 

So the custom code way should only be used when MRL/MRLComm offer no way to do what you want to do. Like using a library not implemented in MRL/MRLComm. But even there you will gain much advantage to try to implement those missing library to MRL/MRLComm, like Mats is doing for many sensor and I did for the neopixel library.

It will also help to keep all your things up to date

Ask for some help if you need, the new MRLComm offer a lot of possibility.

That said, yes it's it's possible to use your custom with MRLComm to communicate with MRL

@juerg

here my comment to your plans

a) copy all MRLComm file to the folder where your arduino script is and merge the .ino file with your code. The file name is not important, but all the code line of the MRLComm.ino must remain in the resulting .ino file. Keep in mind that to have MRLComm work properly, the loop method of the .ino file must remain quick. so avoid long loop and the delay() command.

b) feel free to use whatever msg structure you want, MRL will wrap your msg, send it to arduino that will put your msg avalable in the main loop. The maximum msg size you can use is about 60 bytes, 54 if you route msg to another arduino (see point c)).

c) connect your nano to your mega using the serial port (Rx/Tx). use Serial1, Serial2 or Serial3 on the mega (pin 14-19). The you can have your msg route to your nano easily using the the example I have give in this post http://myrobotlab.org/content/using-multiple-arduino-using-only-1-usb-c…. No need to do any modification to the Mega MRLComm.

To be able to help you answer I will need additional information. Where your wrist servo is connected? On the Mega or on the Nano? What sensor do you use for leveling the hand?

I know MRLComm can compile and run on Nano, but I never really test it and it's not officially supported in MRL. So be warn that not everything may work

 

Hi Calamity

First thanks a lot for your lengthy answer!

At the moment I feel rather comfortable with the small code base in my Nano and think I would rather get lost in the large MRLComm code base

My current code can be viewed here:

https://github.com/MyRobotLab/pyrobotlab/blob/master/home/juerg/Bending…

At the moment I have disconnected Pin 7 (wrist servo) from my Mega. I considered having the servo signal connected to the Mega and the Nano in parallel but my intention was kind of yelled at in an arduino forum :)

As I activate and deactivate the self levelling in a python function in the Mega (as shown here https://github.com/MyRobotLab/pyrobotlab/blob/master/home/juerg/KeepHor…) I thought detaching the servo from the Mega would allow to take over command for the servo by the Nano - but I am clearly convinced that it is a bad idea and might also need additional electrical protection for the pins.

So having the wrist rotate servo only connected to the Nano and then either have the self levelling code in the Nano handle the movement or - with the paused self levelling - position the servo according to what the Mega wants I would feel much better.

So the easiest way for me would be to have a python listener for the wrist servo requests in my MRL main script. In my MRL python script I can then either ignore requests when self levelling is activated or pass the movement, speed, attach and detach requests through the serial line to the Nano.

As orientation device I use the BNO055 as also can be seen in my blog about the self leveling

http://snaptip.com/ezq1qa8d2g/inmoov-self-levelling-hand

calamity

8 years 1 month ago

In reply to by juerg

MRLComm have been modified so it's no longer a big lump a code where it's hard to know what is happening. Every function of the MRLComm have been compartimented into C++ class. So each device can be add without knowing what the rest of MRLComm is doing.

You should take a look at the MrlServo class to see how it work. Each class have have 1 method for initial setting (deviceAttach), some methods to modify parameters and one method (update) that will actually do the processing. update method is called on each MRLComm loop

If I was you, I would try to grab the data you need from the BNO055 and send it to MRL (with a service or to python). Compute the data in MRL and modify the position of the Servo. That way you won't have to have your servo controlled by two pins. Your code just take control of the Servo. It is how services like traking or IK are working.

So Read Data from sensor (arduino side), compute the data (MRL), send signal to the servo (servo.moveTo or servo.writeMicrosecond

 

 

 

as I understand your proposal you would leave out the nano and somehow use MRL I2C service to get data from the sensor.

So can I have a python function in my main script that gets the sensors information?

I will only need to add the "bending" servo and wire it up. The servo control code currently in my Nano.ino can then be moved to my python function.

Looks fairly reasonable to me. So my question is what commands do I need in my MRL script to query the sensor and make my python function get called with the current values of the sensor?

hi juerg

after looking at the bno library, I think the best way to process is by converting the library to a MRL service, the same way Mats did with the MPU sensor

I went ahead and already implement the part of the library you are using in your script (v1707). This is still untested as I dont have the hardware yet, but maybe you can try it when you have the time

here's a sample script

https://github.com/MyRobotLab/pyrobotlab/blob/develop/home/Calamity/bno…

using MRLComm 39 now and made another try with your example script

It sends lots of messages to the device (maybe 100) but only requests 1 read which returns 0.0, 0.0, 0.0

message example: 170,4,18,1,40,1

calamity

8 years 1 month ago

In reply to by juerg

hi juerg

I have ordered a bno055 sensor to be able to test it

I still don't know why it return 0.0, but the thing is that if it get there, it's because the bno055 sensor get recognized

in the begin() method, it first as for the id of the sensor, if it can't get it, it should show bno055 'not found'. If it find it, it reset the sensor and ask for the id again until the sensor complete his reset and answer back, that's why you saw a lot of message to the device. The bno055 library do exactly the same thing, just that you don't see it

It will be easier to debug when I get the sensor. But at least a few thing are going right 

the bno055 service is working fine, it just take a few second before the sensor begin to spit data.

I have modify the python script to poll data every second, it start by returning 0.0, 0.0, 0.0 a few time then it spit number that change with the position of the sensor. I have not verify yet if the data are correct

Right now the bno055 service only do what you ask in your script, but I will expand it to be able to use most of this nice little device can give

thanks, Christian

Was a bit confused by all the stuff the service sends to the device. I get the values now - great! Will need to adapt wireing and then work on the servo control in the python function.

However can't really see how to add this into my main MRL script. I can start the service and set up the python control function but how will that function get called in a short intervall (e.g. each 20 or 50 ms?)

Juerg