Robot Camera

Annex for ESP32
Post Reply
User avatar
TrevorB
Posts: 13
Joined: Tue Jul 06, 2021 10:32 am
Been thanked: 1 time

Robot Camera

Post by TrevorB »

I am working on connecting a TFT touch screen to a small robot camera, using SG90 servos and a PCA9685 module
I have the connections as
connections.png
and a screen as
revised screen.jpg
I will have to redesign the screen as there are no up and down arrows in ASCII.
The code so far is mostly cobbled from others and reports each button push to the wlog screen

screen revised to a lesser challenge

All thats left is to figure out the subroutines and convert some of the buttons to continus press
I assume many of you have been their before me on this...will keep you posted

Code: [Local Link Removed for Guests]

gui.init 20, Yellow  'reserve memory for 20 GUI objects. clears screen to black
txt = GUI.Textline(85,5,300,30, "Robot Camera Control", 3)  'x,y,w,h,text,fontsize
move1 = GUI.Button(35, 40, 100, 100, "RIGHT",5,10 )         'x,y,w,h,text,fontsize, radius
move2 = GUI.Button(135, 40, 100, 100, "store 1",4,10 )      'x,y,w,h,text,fontsize, radius
move3 = GUI.Button(235, 40, 100, 100, "store 2",4,10 )      'x,y,w,h,text,fontsize, radius
move4 = GUI.Button(335, 40, 100, 100, "LEFT",5,10 )         'x,y,w,h,text,fontsize, radius
move5 = GUI.Button(35, 140, 100, 100, " UP",5,10 )          'x,y,w,h,text,fontsize, radius
move6 = GUI.Button(135,140, 100, 100, "store 3",4,10 )      'x,y,w,h,text,fontsize, radius
move7 = GUI.Button(235,140, 100, 100, "store 4",4,10 )      'x,y,w,h,text,fontsize, radius
move8 = GUI.Button(335,140, 100, 100, "DOWN",5,10 )         'x,y,w,h,text,fontsize, radius



but1 = GUI.Button(20, 250, 100, 20,  "load 1",2,10 )         'x,y,w,h,text,fontsize, radius
but2 = GUI.Button(130, 250, 100, 20, "load 2",2,10 )         'x,y,w,h,text,fontsize, radius
but3 = GUI.Button(240, 250, 100, 20, "load 3",2,10 )         'x,y,w,h,text,fontsize, radius
but4 = GUI.Button(350, 250, 100, 20, "load 4",2,10 )         'x,y,w,h,text,fontsize, radius
but5 = GUI.Button(135, 280, 200, 35, "EXIT",4,10 )           'x,y,w,h,text,fontsize, radius


gui.setevent but1, TOUCH, buttonclick1  'set touched event, jump to buttonclick1
gui.setevent but2, TOUCH, buttonclick2  'set touched event, jump to buttonclick2
gui.setevent but3, TOUCH, buttonclick3  'set touched event, jump to buttonclick3
gui.setevent but4, TOUCH, buttonclick4  'set touched event, jump to buttonclick4
gui.setevent but5, TOUCH, buttonclick5  'set touched event, jump to buttonclick6
gui.setevent move1, TOUCH, moveclick1   'set touched event, jump to moveclick1
gui.setevent move2, TOUCH, moveclick2   'set touched event, jump to moveclick2
gui.setevent move3, TOUCH, moveclick3   'set touched event, jump to moveclick3
gui.setevent move4, TOUCH, moveclick4   'set touched event, jump to moveclick4
gui.setevent move5, TOUCH, moveclick5   'set touched event, jump to moveclick5
gui.setevent move6, TOUCH, moveclick6   'set touched event, jump to moveclick6
gui.setevent move7, TOUCH, moveclick7   'set touched event, jump to moveclick7
gui.setevent move8, TOUCH, moveclick8   'set touched event, jump to moveclick8




gui.autorefresh 30, 1 'display gui items automatically each 30ms including touch

wait

subroutines:
moveclick1:
wlog "move 1 pressed"
return

moveclick2:
wlog "move 2 pressed"
return

moveclick3:
wlog "move 3 pressed"
return

moveclick4:
wlog "move 4 pressed"
return

moveclick5:
wlog "move 5 pressed"
return

moveclick6:
wlog "move 6 pressed"
return

moveclick7:
wlog "move 7 pressed"
return

moveclick8:
wlog "move 8 pressed"
return

buttonclick1:
wlog "preset 1 pressed"
return

buttonclick2:
wlog "preset 2 pressed"
return

buttonclick3:
wlog "preset 3 pressed"
return

buttonclick4:
wlog "preset 4 pressed"
return

buttonclick5:
wlog "exit pressed"
return
You do not have the required permissions to view the files attached to this post.
Last edited by TrevorB on Tue Aug 03, 2021 7:53 am, edited 1 time in total.
User avatar
Fernando Perez
Posts: 118
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 62 times
Been thanked: 67 times

Re: Robot Camera

Post by Fernando Perez »

Trevor, I see that in a week you have come a long way in your mastery of the TFT screen. Congratulations!!
A tip, but regarding how to publish source code in the Forum:

- Edit your message by pressing the pencil icon.
- Select the entire piece of code and press the "Code display" icon in the editor (</>).
- Now you should see code in brackets before your code and /code in brackets at the end.
- Replace the code in brackets at the beginning with code=annex in brackets and press the Submit button. Or the Preview button to see the changes before publishing.

All this is not only for aesthetic reasons, but because when I use the automatic translator, it also translates the source code with unexpected results. :o
Last edited by Fernando Perez on Mon Aug 02, 2021 9:32 am, edited 1 time in total.
User avatar
Electroguard
Posts: 272
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 54 times
Been thanked: 127 times

Re: Robot Camera

Post by Electroguard »

Thanks for the practical example TrevorB.

Yeah, the ascii character set contains so many strange chrs which will probably never be used again, so it's a shame they never thought it worthwhile to include arrows... go figure.

No such limitation with pics though, there are loads of free navigational icon sets available, and even just one square pic showing a direction arrow can be rotated and saved to provide the 4 directions, and cloned with different background colour to provide 'active' state pics.

And because a single picture can be better than many letters, you could replace the 4 lonnggg position presets with more larger round coloured preset number pics (most PTZ controllers and cams I've bought have 8 presets, which is just about right for full all-round coverage).

I don't know if CiccioCB's latest 1.43.5 GUI implementation might have anything new to whatever version you are using, so I've copied the Gui.Buttonimage details just in case...
gui.ButtonImage
A combination of a button with 2 images
Img2 = GUI.ButtonImage(x, y, width, height, image1$, image2$ [,toggle], [group] , [background] )

The width and the height are just used to define the touch area, because the size of the image will be defined by the image file content.

The files can be BMP or JPG format.

The BMP can also be 32bits permitting to define a color background with the command gui.setcolor.

Toggle is 0 for temporary (default) or 1 for toggle.

Toggle can also be expressed directly using the keywords MOMENTARY or TOGGLE.

Group is a number that permits to associate interactive buttons together; this permits to deactivate a toggle button when selecting another in the group (like a group of radio buttons).

Background is the background color (for transparent images)

NEW: if the background is -1, the background around the image will be transparent
User avatar
TrevorB
Posts: 13
Joined: Tue Jul 06, 2021 10:32 am
Been thanked: 1 time

Re: Robot Camera

Post by TrevorB »

Thanks everyone for the help and the button fix electroguard
I am trying to keep this as simple as possible because I want to create a multi screen enviroment with this screen just being one choice from a home screen. Hence the exit button to return the the main menu (when it exists) I have revised the post and also spotted a school boy error, the touch command is comented as a jump not a gosub with my return commands I might be driving the stack mad although it is reporting to the wlog correctly

The more pressing probem is I think the touch command is edge triggered, with either monetary or toggle, I need to be able to pole around the button to see if it has a finger on it or not in order to increment a counter and pan the camera.

The choice of graphics is well on the back burner for the moment, but the info is helpful for a revisit

Anybody else been where I am or I am I the first

Sorry to revise the post bit I had the connections wrong and dont want to steer anybody in a wrong direction
User avatar
Electroguard
Posts: 272
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 54 times
Been thanked: 127 times

Re: Robot Camera

Post by Electroguard »

There might be 2 ways to tackle your problem...

The first is to explore new territory - the OnTouch event branches to your chosen subroutine, where you can use any of the 3 touch functions...
TOUCH.X -> returns the X position
TOUCH.Y -> returns the Y position
TOUCH.Z -> returns the touched status (if 1 means touched)

BUT because they are functions, you could use them in a poling subroutine to keep checking their position independent of the on-touch event.
Perhaps use OnTouch to branch to a subroutine which turns OnTouch OFF then keeps poling the TOUCH.X and TOUCH.Y positions for as long as TOUCH.Z =1, then the last thing it does after TOUCH.Z =0 long enough is turn OnTouch on by pointing to your subroutine again ready for the next OnTouch event.


The other possibility is just to use 2 GUI.SLIDERs to provide absolute X and Y positioning, perhaps a horizontal X at bottom and a vertical Y on the side, which would be intuitive and still allow room for all your other buttons.
Image
You do not have the required permissions to view the files attached to this post.
User avatar
Fernando Perez
Posts: 118
Joined: Mon Feb 15, 2021 10:09 pm
Location: Santander (Spain)
Has thanked: 62 times
Been thanked: 67 times

Re: Robot Camera

Post by Fernando Perez »

Trevor, if it's a splash screen you want, you can try this:

Code: [Local Link Removed for Guests]

dim gui(7)
dim text$(7) = "one", "three", "five", "seven", "two", "four", "six", "eight"

gui.init 10, white
control = gui.textLine(150, 20, 200, 30, "Press a key", 4, black, white)

oX = 40 : oY = 70
for col = 0 to 3
  for row = 0 to 1
    x = (100 * col) + oX
    y = (100 * row) + oY
    i = (row * 4) + col 
    gui(i) = gui.Button(x, y, 100, 100, text$(i), 4, 10)
    gui.setEvent gui(i), touch, readTouch
  next row
next col  

gui.autorefresh 50, 1
wait

readTouch:
  id = gui.target
  key$ = "Pressed key " + str$(id)
  gui.setText control, key$
  
  select case id
    case 1: wlog bas.load "/paint.bas"
    case 2: wlog bas.load "/program2.bas"
    case 3: wlog bas.load "/program3.bas"
    case 4: wlog bas.load "/program4.bas"
    case 5: wlog bas.load "/program5.bas"
    case 6: wlog bas.load "/program6.bas"
    case 7: wlog bas.load "/program7.bas"
    case 8: wlog bas.load "/program8.bas"
  end select
  
return
Study the function ret = bas.load file$, it is very powerful.
User avatar
Electroguard
Posts: 272
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 54 times
Been thanked: 127 times

Re: Robot Camera

Post by Electroguard »

I thought Trevor was wishing to keep incrementing or decrementing positional coordinates (move a servo) while holding a navigational touch button, rather than generating OnTouch events for branching elsewhere.

If so, he would not want to keep generating touch events, but instead would want to keep calculating new positional coordinates while the gui touch button was still being held.

Alternatively though, he might make use of the continuous touch and hold drag feature of sliders for absolute positioning, rather than momentary buttons to recalculate relative position changes - cos another consideration is that recalculating relative position change by button would depend on the programmed speed of change and how long the button is held, whereas a quick drag and drop of a slider could rapidly reposition from one extreme to the other.

Maybe I have misunderstood things, though.
Post Reply