United Kingdom
Asked — Edited

Switches And Resistors

Is it possible to add a push button switch, even going as basic as two wires that connect via pushing. Also how do I add a variable resistor. Also will a basic dimmer switch work as a variable resistor? I know these may seem like really daft questions but it helps me alot. Can someone please talk me through it.


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

United Kingdom
#1  

What do you want the push button switch to do? Yes you can add one but without knowing where you want to add it we can't help tell you how to do it. Same for the resistor really.

United Kingdom
#2  

The variable resistor is going to return the position of a joint as the joint is going to be powered by a motor with a reduction gear system. The switch is going to be used to detect when a weight is put into a panel. The switch being placed under it. Not a toggle switch of any kind. The panel will be pushed up with springs, when enough weight is added onto the panel, the switch is triggered. The same switch type I was thing could be added to a foot to detect when the foot is placed onto a surface. Triggered when down for example

United Kingdom
#3  

Dave has used pots on his B9 to find the position, I'm not sure if he has documented it but it'll be worth looking at his B9 project. I think Lumpy has also used the same on his R2D2. I'm not sure if a dimmer switch can be used, I'd guess no but I'm not certain at all.

As for digital switch, yes. Easy. 2 ways to do it, either on the Digital ports or the Analogue.

Analogue, simply put the switch between Signal and Vcc. When it's closed and makes contact it will send 5V to signal giving an ADC value of 255. GetADC(adcport) will give the result.

Digital, almost the same but it's 0 or 1 and can use the Digital Read control or script function.

Script examples;


# ADC Switch
:loop
$switchstatus = GetADC(ADC0)
If($switchstatus = 255)
  # Switch activated
  ControlCommand("closehand",ScriptStart)
  Halt()
EndIf
Sleep(250)
Goto(loop)


# Digital Switch
:loop
$switchstatus = GetDigital(D0)
If($switchstatus = 1)
  # Switch activated
  ControlCommand("closehand",ScriptStart)
  Halt()
EndIf
Sleep(250)
Goto(loop)

United Kingdom
#4  

Excellent thank you. I will look into those they are great. Would that work for variable resistors

United Kingdom
#5  

I believe the ADC one would. As the resistance increases the ADC decreases. Then just have your ifs for specific values or ranges;


$reading = GetADC(ADC0)
If($reading >= 0 and $reading < 50)
  # Do something for this range
ElseIf($reading >= 50 and $reading < 100)
  # Do something for this range
ElseIf($reading >=100 and $reading < 150 or $reading > 250)
  # Do something for these ranges

# and so on
EndIf

#6  

Yes, I am using both methods on my B9 and they work great. The ADC method as Rich describes for push buttons is a good choice. I have several set up like this. Also the Pot (variable resistor) worked better then I had imagined it could. In my scripts to control and monitor the turning of my waist and radar sections I use Variables and Math to find the stop points from readings sent back from the pots through the ADC ports on EZB. You can send an $adcRdrSpecified from any other script or command to get the rotation to stop at any point along the radius. For example:


#Script that calls this needs to use 
#$adcRdrSpecified = "any value between 117 and 153"
#to move the radar.
#Example: $adcRdrSpecified = 125

:Start

  $adcRdrCurrent = GetADC(adc7)

    if ($adcRdrCurrent < $adcRdrSpecified)
    goto(RotateRight)
EndIf

    if ($adcRdrCurrent > $adcRdrSpecified)
    goto(RotateLeft)
EndIf

    If (($adcRdrCurrent >($adcRdrSpecified - 3) and $adcRdrCurrent <($adcRdrSpecified + 3)))
    goto(RotateStop)
EndIf

goto(Start)

:RotateRight
  Set(D9, on)
  Set(D8, off)
Return()

:RotateLeft
  Set(D9, off)
  Set(D8, on)
Return()

:RotateStop
  Set(D8, off)
  Set(D9, off)
Halt()

I've even had great success at ramping the start up and stop of rotation by adding multiple PWM commands, one a little higher then the preceding one at the same time I send the variable command to the movement script. I still need to refine the process. Seems a smaller radius needs different tweaking then a mush larger one. Here's an Example:


:Start
PWM(1.D6,10)
$adcSpecified = 90
controlcommand("Move Waist", scriptstart)
Sleep(0250)
PWM(1.D6,30)
Sleep(0250)
PWM(1.D6,50)
Sleep(2250)

I still need to sit down and clean up all my scripts and my entire B9 project. I have lots of unneeded lines and controlls and junk everywhere. I also need to move my scripts over to the Script Manager but everything seems to be working well for now. I have a lot of actual wrench turning to to on the robot it's self and work on ARC when I want a break or want to see him gain more personality.

Your free to use any of my scripts and I'll help if I can (if I see your post). Rich seems to be the script master around here. In fact I was thinking of asking him to go over my scripts when I cleaned them up a bit to see if there were any way to make them better.

Here's a link to my project thread with lots of pics and vids (including lots of the pots and how they work): My B9 project

Here's the latest copy of my project: B9RobotControl.EZB

Good luck and have fun! Dave Schulpius

United Kingdom
#7  

Thank you so much Rich and dschulpius. That was exactly what I needed to know. Thanks also for the code snippets, I'm writing in c# but I can work it out from there. I'm still testing all these things and when I've put them together I look forward to sharing my project with you all.