DJI OSDK in Windows - c++

I'm trying to get the DJI OSDK up and running from windows environment, but am hitting a few road blocks along the way. Know the SDK has been published for Windows 10, but not yet including the .Net API for M200 / 600 (what I'm trying to interface).
So I first figured my best chance for getting it running on Windows is by trying to run a linux sample application from windows (via Visual studio 2017). Struggled with linux dependencies in the beginning but eventually figured it out by writing a Windows Serial conn class and including pthread.dll for windows (with some minor additional alterations and included #if _WIN32 etc...)
After quite a bit of coding and debugging (also tried Qt sample app via VS tools - whole can of worms on it's own), I'm still struggling with my "Hello world" application from the drone / RPA. (Even the rest works where I export it to a DLL and implement in c# environment, but besides the point).
After connecting to the platform (basically initialization and serial port opening) the Activate function sends your app ID + key to the RPA and receives an acknowledgement: This being my code:
bool threadSupport = true; //disable first so that able to debug
vehicle = new Vehicle(Port, baud, threadSupport, AdvancedSensing);
//test if connection works fine
if (!vehicle->protocolLayer->getDriver()->getDeviceStatus())
{
//not working, delete current instances
delete (vehicle);
vehicle = nullptr; //set back to null pointer
}
DJI::OSDK::Vehicle::ActivateData actData;
actData.ID = appID;
actData.encKey = new char[65];
strcpy(actData.encKey, key);
actData.version = getFWVersion();
ACK::ErrorCode ack = vehicle->activate(&actData, 1);
The activation function returns 'invalid feedback':
STATUS/1 # DJI::OSDK::Win_serial_device::init, L47: Attempting to open device COM21 with baudrate 230400...
STATUS/1 # DJI::OSDK::Win_serial_device::init, L75: ...Serial started successfully.
ERRORLOG/1 # getDroneVersion, L1378: Drone version not obtained! Please do not proceed. Possible reasons:
Serial port connection:
SDK is not enabled, please check DJI Assistant2 SDK -> [v] Enable API Control.
Baudrate is not correct, please double-check from DJI Assistant2 -> SDK -> baudrate.
TX and RX pins are inverted.
Serial port is occupied by another program. * Permission required. Please do 'sudo usermod -a -G dialout $USER' (you do not need to replace $USER with your username). Then logout and login again
ERRORLOG/1 # activate, L1267: Unable to initialize some vehicle components! STATUS/1 # getErrorCodeMessage, L656: Activate STATUS/1 # getCommonErrorCodeMessage, L722: ACK_NO_RESPONSE_ERROR
...Already checked the suggested issues, but can't pick up anything apparent. At this point not knowing if the problem is hardware-, software (with altered code and threading). If anyone with DJI platforms (M-range), or on the DJI dev. team can please assist? I'm desperate to get this working! :(
I've also shared the code solution on Github DJI OSDK Win Console

Hi Im shenghai and I have been running DJI hardware for non-GPS/LIDAR/Vision based autonomous research for 3 years.
It is a typical problem which DJI wont tell you the full list. Here is a checklist that I come up with
(1) Connect API cable first. Then Run OSDK. then connect simulator cable then run DJI assistant. There is proper sequence shit which DJI don't feel obliged to share.
(2) Ensure your cable is 3.3, not 5
(3) Tx Rx swap. Common problem. Can check by realterm
(4) Ensure your DJI go app is running and the controller is powered on b4
start serial connection
(5) Ensure app id and enc key is correct. And the account this id and key are associated is also running in ur tablet. We encounter this issue for some special compassless firmware, if you have close relationships with DJI they will provide u with lots of shit to test.
(6) Ensure your Serial have authority. In ubuntu is sudo chmod a+rw /dev/serial/by-id/usb-XXmanufactoridXX-port0. Windows forgot. haven`t use it for years
(7) Ensure your API is enabled in DJI assistant. Also for a quick check, disconnect and connect to the assistant, ensure API is still checked. We have a bad experience with it. No matter how many time i check, it went uncheck. Took us a while to find the bug
(8) Ensure you are running current Assistant 2. For matrix should be DJI assistant for Matrix. For a different drone, there is a different version. I know its complex. no idea why they do so.
(9) Ensure you OSDK build is complete and functional. No missing dependency or funny errors. It happens a lot with new 3.7 and 3.8 stereo vision system
That's pretty much all I can think so far.

Related

Raspberry pi3: C++ serial communication not working properly (Raspberry pi was working!)

I have a Raspberry PI B+ with a C++ application that is able to communicate with an Arduino. I'm able to read, write, serial connection perfeclty stable.
Now, I bought a Raspberry PI3 in order to have more performances and wifi integrated.
After a lot of time spent, I got the QT application working again but the serial communication wouldn't work.
I connected the serial monitor of Arduino IDE and checked that with RPI 1 it is working fine, and I saw all messages sent following my protocol, so I'm sure that I can analyze what I'm writing out of Raspberry P3.
Unfortunaltely, I receive only weird characters:
I tried different baudrate, for example 115200 and 9600 (expected baudrate!) but the result is different but equally wrong.
I would like to report what I did in my Raspberry P3:
I disabled the serial port for the console (as I understood on the web)
This settings would modify automatically the option:
enable_uart=0
it's strange because in the web I found who is suggesting to enable, who clearly write that it should be disabled because refers to "console over serial".
Then, I added some lines (you can see into red shape) in order to move the bluetooth handling in the miniuart, fixing the cpu frequency to 250 and fixing the default baudrate to 9600.
Then, I disable the bluetooth with this command:
I'm really not sure of that but.. something suggested in some posts.
Finally, this is the setup in my QT c++ application:
Where I changed the name of the port to "ttyS0", (same "serial1").
So.. what I would like to achieve is setup my pi3 serial communication as was working with piB+, connected on same pins GPIO14 and GPIO15.
Doesn't matter to bluetooth, I will not use it.
What I miss or made wrongly?
The PINOUT of Raspberry PI3 seems equal to PINOUT of Raspberry PI B+:
And the PINOUT of Raspberry B+ is:
But I found one interesting thing:
It seems the configuration somehow is wrong because GPIO14 and GPIO15 are both INPUTS !!
I finally fixed!
As I wrote, I found many suggestions on the web but quite often discordant.. so I will report here how I setup my Raspberry p3 in order to work fine.
1) Upgraded my system
sudo apt-get update
sudo apt-get dist-upgrade
2) Enabled the UART console
sudo raspi-config
Advanced options --> serial:
Note: it will automatically set 1 the enable_uart in the file config.txt.
3) Edit config.txt
sudo nano /boot/config.txt
I added basically one line in order to disable the bluetooth port (not used in my case)
I also removed the limitation of cpu frequency to 250, found many times as hint in forums, as you can see it's commented (#).
You can also see the setup of "enable_uart=1" done with raspi-config interface.
4) Edit file cmdline.txt
sudo /boot/cmdline.txt
I removed the piece of string where there was something like:
.... console=serial0,115200 ....
5) Application refers to serial0
6) DONE !
I Hope this step-by-step guide works for someone else or in general will be helpful.

Can't access USB device inside Windows Store App

OK, first I shall point that I am completely new to Windows Apps Development, which is good, since I am trying to develop a Windows Store App for PC to use a PrimeSense Scanner connected via USB. I have asked a more specific question about this here.
This time I have a more generic question, which is more related to Windows Store app development. I am using VS2013 Express and compiling for Win32.
When I compile my application for VS2012 and run it as an execcutable file, I can connect to the scanner perfectly. But I can't do the same with VS2013 and running it as a Store app.
I know the device is connected and the drivers are updated and all dlls file placed in the Widnows System 32 directory.
I have also added all Capabilities to the App Manifest and also added the following Device Capability
<m2:DeviceCapability Name="usb">
<!--OSRFX2 Device-->
<m2:Device Id="vidpid:1d27 0609">
<m2:Function Type="classId:ff * *" />
<m2:Function Type="name:vendorSpecific" />
</m2:Device>
</m2:DeviceCapability>
The vid and pid, obviously match the corresponding codes of the device.
One of the errors I recieve when trying to conenct to the scanner using OpenNI is:
Could not open to "\\?\usb#vid_1d27&pid_0609&mi_00#7&1601586a&0&0000#{c3b5f022-5a42-1980-1909-ea72095601b1}" USB Device not found
This error is quite frustrating since I know the device is connected. So I tend to think that there is some level os specificity on the Windows Store App side of the game that is not enabling my to connect to the device. As I said, I am compiling for Win32.
Is there a chance that the drivers will not work for a Windows Store App. Is there some extra stuff I should do inside the Windows Store App logic that I am not doing and that is necessary to connect the USB device? I am sorry, but I am completely new to Windows Store App development.
Thank you.
You can't do that from metro apps.
You typically create a handle to that usb device by calling CreateFile with that object mananger path as the file to 'create'. CreateFile is not allowed in metro apps - "desktop apps only" - and its 'replacement', CreateFile2, specifically doesn't allow opening object manager objects.
Furthermore, the documentation for CreateFile2 states that in metro apps this function can only open files and directories (and not things like pipes, mailslots, consoles, etc.).
See also this post on social.msdn
Unless I missed something, I don't think this is possible.

Bluetooth C++ Winapi Discoverable

I'm using source codes based from the following links w/my broadcom bluetooth device:
I want to make a bluetooth server that automatically starts and other devices can pair with it.
http://www.codeproject.com/Articles/252882/Bluetooth-Server-Programming-on-Windows
http://msdn.microsoft.com/en-us/library/windows/desktop/aa362932(v=vs.85).aspx
I can get the code to compile fine, allegedly the server starts, it tells me my local bluetooth device, the server port, but I cannot see the advertisement when I scan for bluetooth devices w/my iphone or ipad.
Device manager reports my bluetooth driver as functional. I'm doing this in a vm machine on win 7.
Both links say nothing about BluetoothEnableDiscovery() function. Would I need this? I tried but not sure how it works.
Everything looks ok, in the entire process I don't receive a single error. I just think I need to set it to discoverable some how or make it advertise so my other devices can see it and pair with it.
If you have any ideas, I would appreciate them. Thanks.
EDIT: Would anyone know how I can change between Secure Simple Pairing modes, or set a a 4/8 digit key for pairing in winapi c++?
With Microsoft BT stack (even with a Widcomm dongle), under Win7, your server has to expose a 'service' first.
it can be "Discoverable' but without any service exposed, no-one will "see" your server from the outside.
Check out WSASetService: https://msdn.microsoft.com/en-us/library/aa362921(v=vs.85).aspx
PS: the service will live during your app execution only...

Testing cocos2d iPhone using Calabash-iOS

Some people suggested https://github.com/calabash/calabash-ios for iOS tests. I am using cocos2d-iphone, can I write tests for it using calabash?
Still calabash turned me off because it says it will only work with the simulator which is not enough and also if devices I have to use a service which just sounds like trouble. Any clean solution?
After completing this guide you will be able to run tests locally
against the iOS Simulator. You can also interactively explore and
interact with your application using the Calabash console.
Finally, you will be able to test your app on real, non-jailbroken iOS
devices via the LessPainful service.
Edit: https://github.com/calabash/calabash-ios/wiki/07-Testing-on-physical-iDevices suggests that device testing is possible... I guess I'll just have to try it myself...
Edit 2: I did get it all working. Even hooking up to a remote device that is not even plugged into the computer (just needs to be on same WIFI). When hooking up to the device it helps using the UDID of the device, this was not stated on calabash-ios docs, or I missed that.
For anyone coming here later, this is the final command that will work:
DEVICE_ENDPOINT=http://192.168.36.180:37265 BUNDLE_ID=build/tabeyou-cal DEVICE_TARGET=thelongudidofyourdevicegoeshere OS=ios6 cucumber
Just replace the ip to the ip of your device, the udid, and BUNDLE_ID which should be the target name (I think).
My current question is, how would I identify cocos2d stuff like CCMenu, CCSprite etc? These all seem to support accessibility identifiers and I'm sure the Ruby-iOS part could find anything under the hood - in turn that should make it possible to write tests interacting with cocos2d elements.

Ping "no resources" - what can cause that?

I have a strange problem - after my C++ application runs for 39 hours on Windows XP, the network is broken and the application fails. Seen that several times. When I try to "ping localhost", the prompt says "no resources". I found this thread in Internet, where people advice to make "ipconfig /renew".
The thing is I just want to know, what actions (Windows API calls) causes that. I'm nearly 100% sure that the problem is in the network card (because the other card works well), but I just want to understand, what my actions cause that.
Unforunately, my application consists of megabytes of code, so I can't just uncomment a few lines to see if I can reproduce error now.
Is there any list of Windows API calls that are executed by network card driver? For instance, "sendto" is most likely executed by driver, because it sends data to network.
Is there any test (like Acid test for browsers), which can show if network driver does not behave correctly?
It kind of sounds like you've run out of sockets. Are you sure you're freeing the sockets once you've used them?
Make sure that your network card is updated with latest driver or re install the driver and then restart the machine once.