# JJRobots COMMUNITY

Full Version: BRobot ESP32
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

First I want to say what a great design you guys have come up with for the BRobot. I bought/built the kit a few weeks ago but after getting it going I have decided to create my own version using the ESP32, MPU9250, AMIS 30543 stepper drivers for stepper control and a custom PCB to interface it all. I also have added IR sensors for obstacle avoidance and plan on making it fairly autonomous also. I have it up and balancing and also hooked upto an RC receiver for control with my spektrum radio.

With the ESP32 I am able to replace the arduino leonardo and use just the one ESP32 to handle WIFI, and everything else in one chip. Most of the code I have written is somewhat new and quite different as the ESP32 I am not using arduino libraries. However the control loop for balance and control is the same in principle as the original code. I am curious as to a couple of lines of code that I assume are empiracally calculated but I would like to understand where these come from.

Code:
`int16_t angular_velocity = (angle_adjusted - angle_adjusted_Old) * 90.0; // 90 is an empirical extracted factor to adjust for real units`

Can you guys help explain what the 90.0 factor is. Also I don't see where there is a time delta to compute a velocity. Guessing maybe this is built into the 90?

Code:
```#if MICROSTEPPING==16   speed = speed_M1 * 46; // Adjust factor from control output speed to real motor speed in steps/second #else   speed = speed_M1 * 23; // 1/8 Microstepping #endif```

This is where you are setting the speed of the steppers. Input to this function is the integration of the velocity output from the PD controller which is an acceleration. For the life of me though I can not figure out what is actually happening here to get the acceleration to a velocity or what this 46/23 factor is for. I know it is some multiple of the microstepping but this is not clear to me. Can you help me out of the intent here?

To sum it all up I do have a working implementation that works well and I look forward to sharing my project with the community! If anyone is interested in my project please let me know. I plan on posting some videos soon.

Thanks!
I thought there is now an Arduino project that can be used to program the ESP32.
https://github.com/espressif/arduino-esp32

I thought the speed_M1 * 46 is the number of steps that they want in one second based on the size of the wheel.

Mike
Hi qjones !
You say you are using a MPU-9250, did you modify the B-robot code to make it work ? I'm also trying to use a MPU-9250 on a arduino pro micro but the unmodified B-robot code doesn't seem to work with it.
Thanks
(04-01-2017 09:43 AM)iseries1 Wrote: [ -> ]I thought there is now an Arduino project that can be used to program the ESP32.
https://github.com/espressif/arduino-esp32

I thought the speed_M1 * 46 is the number of steps that they want in one second based on the size of the wheel.

Mike

You are correct there is the arduino port. Couple of reasons I chose to go with what they call the esp-idf libraries.

1. I have been doing arduino for quite some time and was looking to branch out to slightly more advanced ways of coding and getting some performance boosts and ability to use cheaper chips in the future.

2. I think the arduino-esp32 has probably caught up now but it was not as feature complete as the other side initially. Either way since I was using different hardware the code was going to have to change either way. I have it working well I just would like to be able to know what some of the "magic" numbers are for my own understanding.

I am sure the wheel diameter is probably in there somewhere potentially. But from looking at the forums it seems to work pretty well with different sized wheels by just adjusting the PID gains and nothing else...

(04-01-2017 12:41 PM)xStouf Wrote: [ -> ]Hi qjones !
You say you are using a MPU-9250, did you modify the B-robot code to make it work ? I'm also trying to use a MPU-9250 on a arduino pro micro but the unmodified B-robot code doesn't seem to work with it.
Thanks

I did modify the original code quite heavily. Basically started from scratch and pulled in parameters and some of the balancing code. I ended up using the sparkfun MPU-9250 library as a reference and all seems to work well. JJRobots modified the DMP to make it more lightweight/efficient that might have something to do with it. If you can pull that library in a get your tilt angles it should not be to hard to change out. I need the magnetometer for a heading read in my navigation is why I went with it. I can help you out if you need.

Thanks,
(04-01-2017 06:25 PM)qjones Wrote: [ -> ]I did modify the original code quite heavily. Basically started from scratch and pulled in parameters and some of the balancing code. I ended up using the sparkfun MPU-9250 library as a reference and all seems to work well. JJRobots modified the DMP to make it more lightweight/efficient that might have something to do with it. If you can pull that library in a get your tilt angles it should not be to hard to change out. I need the magnetometer for a heading read in my navigation is why I went with it. I can help you out if you need.

Thanks,

I already tried the Sparkfun MPU-9250 DMP library, but it does not work with pro micro, SRAM is too low when using DMP examples codes (Global variables use 3769 bytes (147%) of dynamic memory, leaving -1209 bytes for local variables. Maximum is 2560 bytes.). The same example code compiles well for Atmega1284 though (16KB SRAM vs 2.5KB for Atmega32u4). I also tried with an ESP8266 (ESP12E), but the compiler shows errors related to the library.

Using the non-DMP library and Mahony quaternions algorithm, I could get angles with a ~100Hz refresh rate but I did not succeed porting it to B-robot code. I don't understand the code well enough yet. I also tried from scratch by using the Robot Code Breakdown found in another thread as a base, but it is very different and I did not succeed either.

My goal is to get it work with magnetometer for basic navigation, and control it via bluetooth (HC-05). Once it works I will add ultrasonic (HC-SR04) and IR sensors, and replace bluetooth with raspberrypi + camera. The Atmega1284 may be a good option after all

Your help is really appreciated, many thanks !
(04-02-2017 01:25 AM)xStouf Wrote: [ -> ]My goal is to get it work with magnetometer for basic navigation, and control it via bluetooth (HC-05). Once it works I will add ultrasonic (HC-SR04) and IR sensors, and replace bluetooth with raspberrypi + camera. The Atmega1284 may be a good option after all

Your help is really appreciated, many thanks !

I have similar plans and am making decent progress. Just got some odometry code written yesterday and am about to start in on basic navigation today. In my head this should go pretty well. We'll see what happens... I also have added 2 IR sensors for obstacle avoidance. Will hopefully post some videos soon.
Hi qjones...
I have also been doing some decent progress. I realized I was using an outdated BROBOT code from github (EVO1). I re-started from scratch using the EVO2 code, and everything is now way easier. I just deleted the ESP and servo parts, built my electronics, adapted the motors pins in the code, and it just works on first try with MPU-9250 without modifications (minus the magnetometer, of course). I'm really surprised, I was almost sure my code would not work, or that I would spend many hours making it stable.
I am now in the process of adding bluetooth remote control. Then, I will start working on the autonomous navigation. This is something I'm already familiar with, so I think it will be easy.

Video of the first try, just minutes after the last solder point :

Great job, JJRobots. Your EVO2 is really cool !!!
Well, thank you! Really impressed with the work you are doing. Please keep everyone updated!
We are working now in the Google Blockly feature. I have attached the "BLOCKLY Launcher" to this message (Windows OS for now).
This is the BETA version (functional but still a BETA). NOTE: the blockly feature is included in the latest B-robot EVO 2 code: https://github.com/jjrobots/B-ROBOT_EVO2
This could help you with the autonomous navigation as it provides simple instructions via WIFI (you can use the computer to guide the B-robot)

Steps to use the Blockly:
1) Extract the rar file
2) Connect the B-robot to your computer
3) Launch the "BROBOT_Blockly.exe"
4) Wait for the browser to open up a webpage
5) Use blockly (example attached). Send the commands to the robot clicking on the top right red button [attachment=203]
Thank you also for the kind words !
Again, I've been doing some decent progress, the basic bluetooth remote control is now fonctionnal :
This thing is getting really fun
But before going further, I have to design some circuitry for checking each of the 3 cells. (Initially I planned to build a standalone circuit with a ATtiny84 and 3 status leds, also connected to the main arduino via I2C. I like modular designs )

I'm also very interested in your blockly features, but my robot is bluetooth controlled. I choosed bluetooth because it is easier to code, the android interface is very easy to adapt, and it just works without shutting down internet on the phone.
- replacing the bluetooth on the robot with an ESP8266,
- building a small battery powered bluetooth-wifi gateway using another ESP8266 in AP mode
The robot could automatically choose to connect to the gateway, or to an existing wifi network.
Then, I could still control the robot using bluetooth on the phone, or wifi only, and also use the blockly features.
(Edit : and it would just work with my other bananapi wifi tank...)

On a side note for those using a Arduino Pro Micro : the regulator on the Pro Micro is crap. I'm powering the arduino directly via the 12v from the cells using the RAW pin, and today the regulator started to output 2.3v only. So I soldered a MCP1702-3302 directly on RAW-GND-VCC pins and everything is now working well at 3.3v (arduino pro micro 5v/16MHz running at 3.3v is out of specs, but I knew it would work. I was not so sure about the HC-05 bluetooth module and the A4988). I did not even bother to remove the old regulator. However it would not be enough to power a ESP8266...
Hi,
did you had success in building a controler with a ESP8266?

I'm looking for a simple controler for B-Robot.

I tried to connect 2 ESP8266 (for a different project) but the latency was too much. :-(

Any hint/link to a project is appriciated.

cu
neunmann
Reference URL's
• JJRobots COMMUNITY: http://forums.jjrobots.com/index.php
• :