Coding a sequence of movements into JumpingSumoSample


#1

Product: [Jumping Sumo/Jumping Race/Jumping Night]
Use of libARController: [YES] (Only for ARSDK)
SDK platform: [Unix]
Reproductible with the official app: [YES]

Hi guys, I’ve been playing around with the JumpingSumoSample.c file and tried to replace the spacebar-jump command provided with a specific sequence of commands like go straight, turn left a little, then go straight again.

But after it performs the turn command, the next straight command after that causes it to spin on one wheel. it seems as if the bot performs the straight command for the stipulated sleep+usleep time, but for only one wheel.

Below is a segment of the code i added:
> error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 1);

        error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 50);
        sleep(1);
        error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 0);
        sleep(1);
        error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 1);
        error = deviceController->jumpingSumo->setPilotingPCMDTurn (deviceController->jumpingSumo, -50);
        usleep(260000);
        error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 0);
        sleep(1);
        error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 1);
        error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 50);
        sleep(1);

so it will go straight,pause, turn left, pause, then go straight again, but at the straight again segment at the bottom it just spins on one wheel.

as can be seen ive tried turning off the flag in between the movement segments.

I’m pretty bad at coding and i realise the above looks pretty messy (still trying to improve T_T).

Any help anyone can provide will be greatly appreciated.


#2

Hi,

Without testing the following code, here is what I would do:

// put flag to 1 because we will need it all the way along
error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 1);

// go straight for 1 second
error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 50);
sleep(1);

// stop going straight
error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 0);

// turn for a small amount of time
error = deviceController->jumpingSumo->setPilotingPCMDTurn (deviceController->jumpingSumo, -50);
usleep(260000);

// stop turning
error = deviceController->jumpingSumo->setPilotingPCMDTurn (deviceController->jumpingSumo, 0);

// go straight again for 1 second
error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 50);
sleep(1);

// stop going straight
error = deviceController->jumpingSumo->setPilotingPCMDFlag (deviceController->jumpingSumo, 0);
error = deviceController->jumpingSumo->setPilotingPCMDSpeed (deviceController->jumpingSumo, 0);

Hope this helps,
Best regards,
Djavan


#3

Hey Djavan,

IT WORKED!! thanks so much!!!
Sorry for the late reply, i had suddenly taken ill and havent been back to a desk since i last asked the question.

I have another question, I would like to be able to put a series of commands into the terminal and have the jumping sumo read it as a series of movement commands. I’m trying to understand how to do this coding myself and as far as i can see, the
ihm = IHM_New (&onInputEvent);
line does something to read input commands, but seemingly only 1 key press at a time.

Do you have any advice on how to continue here?

Thank you so much for the tip before i really appreciate it.

Best regards,
Sean


#4

Hi,

Glad it worked :slight_smile:

The samples use ncurse to get the keyboard inputs. It seems that you can’t get multiple inputs with ncurse.

Regards,
Djavan


#5

Hey Djavan, It’s been awhile and i just wanted to thank you again for your help as well as give an update to my project situation and ask for help on a new problem :P.

I ended up giving up using C in favor of finding the node-sumo repo on github. I’ve for the most part achieved my goal of getting the sumo to follow a set of commands AND now enabling the sumo to follow a black square around using node-opencv. I’ll share my github later once i put up the code ( hopefully i can figure it out… lol) .

However i also have faced another issue regarding trying to use the same code on another sumo bot version. I am originally using the Jumping Night drone, but now i need to get the same .js code to work on the Jumping Race version. When i try to run it on the race, i receive these errors:

Unhandled PROJECT_COMMON commandClass: 18, commandId: 2
battery: 36
Unhandled COMMON_CLASS_COMMONSTATE commandId: 9
Unhandled PROJECT_COMMON commandClass: 29, commandId: 3
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled PROJECT_COMMON commandClass: 25, commandId: 0
Unhandled COMMON_CLASS_COMMONSTATE commandId: 8
video streaming state changed

It seems that the error messages come from this part of the node-sumo library (link here https://github.com/forgeByAcision/node-sumo/blob/master/lib/sumo.js) from around line 206. They also seem very tied to constants.js (link here https://github.com/forgeByAcision/node-sumo/blob/master/lib/constants.js) .

I’ve tried looking into the original ARCOMMANDS_Ids.h and copy lines from that into constants.js but to no avail ( also i really dont think i understand the process :P)

Any insight would be appreciated

Best Regards,
Sean


#6

Hey guys,

i said i would put up my completed code so here it is… really really late. Thanks everyone on the forum for all your help. I hope this helps other people with similar projects as well.

The code enables the jumping night and jumping race to be controlled using javascript to:

  • first follow a set of directional commands " w a s d " (2 w’s = forwards twice)
  • then it uses OpenCV to track a rectangular shape of specified color
    - once it finds the shape, it will maintain distance from the shape:
    - if you move it closer it will back up , further away and it will try to get closer
    Below are my repositories for the jumping night and the jumping racer


for the race drone. there’s an additional file that will allow the race drone to track a blue circle ( i used a foam sphere wrapped in blue felt)

As for how everything else works i kind of forgot… its been awhile. I hope this helps

Edit: i forgot to post my project video!

Thanks again